Results 1 to 11 of 11

Thread: Detect if mouse or keys are being pressed

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Utah
    Posts
    397

    Detect if mouse or keys are being pressed

    How can I detect if the mouse is being moved or the keys on the keyboard are being pressed?

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Over a form? For basically any control, the movement of the mouse invokes the MouseMove event, and a click of the mouse invokes the Click event.

    You can check them out in the events list for each control.

    For example,

    VB Code:
    1. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2.  
    3. msgbox "X is: " & X & ", and Y is: " & Y
    4. 'do something
    5.  
    6. End Sub


    HTH

  3. #3
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431
    And keys being pressed can be similarly detected by the KeyUp, KeyDown, or KeyPress events (if you need to make it a quick and dirty global hook, you can use GetAsyncKeyState API, although I won't go into that unless you need it [the simpler the better in my opinion ])
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Utah
    Posts
    397
    sorry bout that, but i mean like anywhere on the screen, even when the app is minimized

  5. #5
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: Detect if mouse or keys are being pressed

    Originally posted by Narfy
    How can I detect if the mouse is being moved or the keys on the keyboard are being pressed?
    Relating to your App, or to the screen? (ie any 'other' app/window)

  6. #6
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Ignore my last.


    You will meed to API/SubClass... brb


    EDIT: What jemidiah said...


    Bruce.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Utah
    Posts
    397
    im a newb vb programmer, i know how to user GetAsyncKeyState api, but i want it more simple, so could some please explain the keyup and keydown stuff?

  8. #8
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    Originally posted by Narfy
    ..but i want it more simple, so could some please explain the keyup and keydown stuff?
    In this case you can't those Events. You have stated that your app may be Minamised, hence the KeyPress (of your app) won't fire.

    Thats why GetAsyncKeyState was suggested.


    Bruce.

  9. #9
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431
    And for the cursor, you can use the GetCursorPos API in the loop you'd use for the GetAsyncKeyState API to capture the current mouse position. Now, detecting mouse clicks.... I'm actually not sure about
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

  10. #10
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148
    What I suggest you do is install a WH_JOURNALRECORD hook. This will be triggered whenever a mouse event or keyboard event occurs...

  11. #11
    Only Slightly Obsessive jemidiah's Avatar
    Join Date
    Apr 2002
    Posts
    2,431
    Nice suggestion
    The time you enjoy wasting is not wasted time.
    Bertrand Russell

    <- Remember to rate posts you find helpful.

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