Jump to content

Getting mouse to click on a keyboard stroke


Recommended Posts

Hello,

I would like to setup AutoIt to perform a simple left click when prompted by a keystroke. There are 4 different buttons I press repeatedly, all side by side, and it would be quicker if I didn't have to move the mouse and could just enter keystrokes, say numbers 1-2-3-4 or letters a-s-d-f.

I have tried these commands but they don't seem to be working for me:

HotKeySet("{a}", MouseClick("left", 35, 190))

HotKeySet("{b}", MouseClick("left", 35, 225))

and

If Send("a") Then MouseClick("left", 35, 190)

If Send("b") Then MouseClick("left", 35, 225)

Please help a noob with a simple script! =)

Link to comment
Share on other sites

hi stn9060,

if you look at the help file for the HotKeySet function, you'll see that it doesn't accept code but just the name of a function to call. E.g.

HotKeySet("^q", "_myMSG") ;--> Calls function _myMSG on pressing CTRL-q

Func _myMSG()
   MsgBox(0, "Wow!",  "You've pressed CTRL-q!")
EndFunc
Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
Link to comment
Share on other sites

Thank you Hannes! I have got it working using this script. Do you see any room for improvement or a more efficient script?

HotKeySet("a", "Click1")

Func Click1()

MouseClick ("left", 35, 190)

EndFunc

HotKeySet("s", "Click2")

Func Click2()

MouseClick ("left", 35, 225)

EndFunc

HotKeySet("d", "Click3")

Func Click3()

MouseClick ("left", 35, 260)

EndFunc

Sleep(2147483647)

Link to comment
Share on other sites

HotKeySet("a", "Click1")
HotKeySet("d", "Click3")
HotKeySet("s", "Click2")
HotKeySet("x", "_Exit")

While 1
Sleep(100)
WEnd

Func Click1()
MouseClick ("left", 35, 190)
EndFunc

Func Click2()
MouseClick ("left", 35, 225)
EndFunc

Func Click3()
MouseClick ("left", 35, 260)
EndFunc

Func _Exit()
Exit
EndFunc

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...