dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: SendKeys -> Keep it pressed

  1. #1
    Join Date
    Apr 2002
    Location
    Belgium
    Posts
    125

    SendKeys -> Keep it pressed

    Hello,

    How can i send a key, but keep it pressed? With the SendKeys function it only gets pressed and released.

    Thanks
    Bert Willekens,

  2. #2
    Join Date
    Jan 2003
    Location
    7,107 Islands
    Posts
    2,487
    You can use the Timer together with the keybd_event or even the SendKey function to eventually generate the event..

    Code:
    Option Explicit
    
    Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    
    Private Sub Form_Load()
      Timer1.Interval = 250
    End Sub
    
    Private Sub Timer1_Timer()
      keybd_event vbKeyO, 0, 0, 0
    End Sub
    Busy

  3. #3
    Join Date
    Apr 2002
    Location
    Belgium
    Posts
    125
    its a solution, but not a good one, then it will flicker all the time, on, off, on, off, on, off, on, off
    Bert Willekens,

  4. #4
    Join Date
    Jan 2003
    Location
    7,107 Islands
    Posts
    2,487
    Ok fine So what's the purpose anyway??.. What's the use?.. What are you trying to accomplish??..
    Busy

  5. #5
    Join Date
    Apr 2002
    Location
    Belgium
    Posts
    125
    example: Like, when u want to put a light on, u r not gonna keep ure finger all the time on the button to keep it on. So i want to make something, that simulate my finger When i do it with a timer, it will flicker.
    Bert Willekens,

  6. #6
    Join Date
    Jan 2003
    Location
    7,107 Islands
    Posts
    2,487
    Well, actually everytime you press a key the keyboard handler initiates the task for the OS to generate the mesage that will be pumped on to the system. So as long as you didn't release the key (State) the OS keeps on pumping the message in order to generate the events. So that's it, I use the timer to eventually generate the event (KEY_DOWN).. But if you don't need the event then you may just call the function once and forget about the timer..

    'KEY_DOWN
    keybd_event vbKeyO, 0, 0, 0

    'KEY_UP
    keybd_event vbKeyO, 0, &H2, 0

    It's the keyboard state that determined the on/off.. Probably you can use the GetAsyncKeyState to monitor the state of the key (PRESS/UNPRESS), you will know
    Last edited by Thread1; July 25th, 2003 at 06:30 AM.
    Busy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)