|
-
Oct 22nd, 2003, 10:45 PM
#1
Thread Starter
Hyperactive Member
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?
-
Oct 22nd, 2003, 10:48 PM
#2
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
-
Oct 22nd, 2003, 10:55 PM
#3
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.
-
Oct 22nd, 2003, 10:56 PM
#4
Thread Starter
Hyperactive Member
sorry bout that, but i mean like anywhere on the screen, even when the app is minimized
-
Oct 22nd, 2003, 10:57 PM
#5
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)
-
Oct 22nd, 2003, 10:57 PM
#6
Ignore my last.
You will meed to API/SubClass... brb
EDIT: What jemidiah said... 
Bruce.
-
Oct 22nd, 2003, 11:05 PM
#7
Thread Starter
Hyperactive Member
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?
-
Oct 22nd, 2003, 11:19 PM
#8
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.
-
Oct 22nd, 2003, 11:25 PM
#9
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.
-
Oct 23rd, 2003, 03:05 AM
#10
What I suggest you do is install a WH_JOURNALRECORD hook. This will be triggered whenever a mouse event or keyboard event occurs...
-
Oct 23rd, 2003, 08:05 PM
#11
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|