How can I detect mouse clicks and keyboard presses?

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
dhlsWkr8
Newbie
Posts: 1
Joined: Thu Jun 23, 2005 10:32 am

How can I detect mouse clicks and keyboard presses?

Post by dhlsWkr8 » Thu Jun 23, 2005 10:46 am

Hi. I have a question. How can I detect mouse clicks and keyboard button presses? For example, when the user clicks somewhere in the screen, the script will take the x and y coordinates of the clicked pixel and do something with the coordinates. For another example, each time the user presses "A" from the keyboard, the script will do something. Thank you.

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Jun 23, 2005 7:05 pm

I think what you're looking for is WaitKeyDown. Read the documentation its fairly straightforward. I have never been able to get the virtual keys to work for mouse clicks. I have circumvented this by leaving a message to the user to position the mouse as needed and then press a key (usually the space bar). And using GetCursorPos (GCP) to grab the cursor coordinates. Here is an example.

MDL>Position the cursor and press the Space Bar.%CRLF%Pick OK to continue
WaitKeyDown>VK32
GCP>x,y
MDL>mouse positioned at %x%,%y%

Hope this helps,
Dick

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts