Results 1 to 5 of 5

Thread: How can I tell if a key was pressed outside of my app?

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Posts
    8

    Post

    I have a program that is used to test a product. It has it's own screensaver built in so I can easily update the screensaver's message if a warning arises to alert the operator. I have it set up to start the screensaver after 60 sec of inactivity. I can monitor the mouse anywhere on the screen, but I can not tell if a user is typing outside of my app. So the screensaver tends to kick in if you are, say, typing a long e-mail and don't touch the mouse. I found some code that looks for specific "Hot-keys", but I ned something that fires for any key press, to reset my counter.
    Anyone have any ideas???

    Thanks!
    Glenn

  2. #2
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088

    Post

    There's an API function GetKeyState or something... try this

    ------------------
    [email protected]
    ...
    Every program can be reduced to one instruction which doesn't work.


  3. #3
    Addicted Member Razzle's Avatar
    Join Date
    Jan 2000
    Location
    Berlin, Germany
    Posts
    161

    Post

    It's GetAsyncKeystate
    You can use it in a timer for example:

    Private Sub Timer1_Timer()
    For i = 1 To 255
    If getasynckeystate(i) <> 0 Then
    'key has been pressed.
    End if
    Next i
    End Sub

    ------------------
    Razzle
    ICQ#: 31429438
    What is the difference between a raven?
    -The legs. The length is equal, especially the right one.

  4. #4
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088

    Post

    Mhm, I meant another function similary to this. But you can get the whole keys in one call like

    -
    Dim Keys(255) as Long

    GetKeyboardState Keys
    -

    Something like that... Don't know which function u finally need...

    ------------------
    [email protected]
    ...
    Every program can be reduced to one instruction which doesn't work.


  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Posts
    8

    Post

    Thanks guys. That will work, It is a bit better than what I had found.

    If I use the array to get the results, is there a faster way than this to see if any of the array has been set to <> 0?
    for x = 0 to 255
    if Keys(x) <> 0 then
    Presed = True
    end if
    next
    if Pressed = True then ....

    Thanks again for the help!

    Glenn

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