Results 1 to 7 of 7

Thread: Key is down or up? *resolved*

  1. #1

    Thread Starter
    Hyperactive Member Dmitri K's Avatar
    Join Date
    Sep 2002
    Location
    West Palm Beach, FL
    Posts
    444

    Key is down or up? *resolved*

    Following code is in the timer with interval set to 100
    VB Code:
    1. If GetAsyncKeyState(VK_F12) Then
    2. ....
    3. num = num + 1
    4. end if
    The problem is if i keep F12 down without releasing it, num will increase by 1 every 100 milliseconds. Is there anyway to make it work so num = num + 1 will ONLY execute when F12 has been released, so if I press F12 when num = 0, num will stay 0 until I depress F12, and when I press it again num will equal to 1, and so on. With each key press num will increase by 1, but with continuous key press, num will not change.
    Last edited by Dmitri K; Mar 21st, 2003 at 07:57 PM.

  2. #2
    Fanatic Member laserman's Avatar
    Join Date
    Jan 2002
    Location
    Wales U.K
    Posts
    775
    Without checking the code.

    Could you do it in the key up event. start the timer when the keyup activates
    Maybe be totally wrong.

    Cheers

  3. #3

    Thread Starter
    Hyperactive Member Dmitri K's Avatar
    Join Date
    Sep 2002
    Location
    West Palm Beach, FL
    Posts
    444
    No, unfortunately no. I need to track global keypress, not just application's process.

  4. #4
    Fanatic Member sql_lall's Avatar
    Join Date
    Jul 2002
    Location
    Up Above (i.e. AUS)
    Posts
    571

    Talking Sure

    No problem.
    Have some boolean variable, i.e. Public F12_DOWN as boolean.

    Then do stuff like this:

    If GetAsyncKeyState(VK_F12) Then
    F12_DOWN = true
    Else
    If (F12_DOWN)
    ___F12_DOWN = false
    ___...Put code here...
    End if
    End if

    This *should* run the code only when F12 is not pressed AFTER it has been pressed, i.e. when its released

    (N.B. this is just an approximation, i'm never sure about the If..else rules )
    sql_lall

  5. #5
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    A timer is not a good way to track a global keypress - what happens if they press it twice between timer clicks, and the timer code is quite a heavy drain on the system.

    If you want to see all the keypresses system wide, install a system wide journal or low level keyboard hook as per this example or if you just want to be notified when a given key is pressed system-wide then use the RegisterHotkey API call as in the MCL Global Hotkey control
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

  6. #6

    Thread Starter
    Hyperactive Member Dmitri K's Avatar
    Join Date
    Sep 2002
    Location
    West Palm Beach, FL
    Posts
    444
    Well Hotkey sounds great, but I stayed away from any 3rd party controls thruout the project, I don't want to use them now either.

    Thanks

  7. #7
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    but I stayed away from any 3rd party controls thruout the project, I don't want to use them now either.
    Then I'd suggest you download the source code and add it to your project thus have no external dependencies...
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

Posting Permissions

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



Click Here to Expand Forum to Full Width