How can I detect if the mouse is being moved or the keys on the keyboard are being pressed?
Printable View
How can I detect if the mouse is being moved or the keys on the keyboard are being pressed?
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:
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) msgbox "X is: " & X & ", and Y is: " & Y 'do something End Sub
HTH
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 ;)])
sorry bout that, but i mean like anywhere on the screen, even when the app is minimized
Relating to your App, or to the screen? (ie any 'other' app/window)Quote:
Originally posted by Narfy
How can I detect if the mouse is being moved or the keys on the keyboard are being pressed?
Ignore my last.
You will meed to API/SubClass... brb
EDIT: What jemidiah said... :)
Bruce.
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?
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.Quote:
Originally posted by Narfy
..but i want it more simple, so could some please explain the keyup and keydown stuff?
Thats why GetAsyncKeyState was suggested.
Bruce.
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 :confused:
What I suggest you do is install a WH_JOURNALRECORD hook. This will be triggered whenever a mouse event or keyboard event occurs...
Nice suggestion :cool: