How to turn a keypress into a mouse click?

280 views
Skip to first unread message

James Davis

unread,
May 22, 2019, 8:22:30 PM5/22/19
to autokey-users
I want a script that  waits indefinitely for a single key, the tilde, to be pressed and whenever that key press is detected, the left mouse button is clicked. 

How would I do this?

Joe

unread,
May 23, 2019, 4:12:52 AM5/23/19
to autoke...@googlegroups.com
A few thoughts:

If you just assign tilde as the hotkey, then there's nothing waiting
except AutoKey itself (which already knows how to do that and is doing
it anyway.)

If you do this, you will lose the normal tilde key unless you use an
appropriately restrictive window filter so it only works on certain
windows. If instead, you use a modifier key with tilde as the hotkey,
then that would be very unlikely to conflict with anything else.

Mouse events are listed in the API documentation
https://autokey.github.io/index.html

mouse.click_relative_self(0, 0, 1)

looks like it will do what you want. It will do a left click wherever
the mouse cursor currently is positioned (unless you have a left-handed
mouse).

If you need to be able to toggle this feature on and off, that will take
a bit more thought and effort.

Using an indefinite/infinite loop script:

Although AutoKey is multi-threaded and will allow it, some of the
libraries it uses aren't great with this, so writing scripts that run
forever might make AutoKey unstable - which might affect the rest of
your desktop environment (DTE).

You'd also have to figure out how to catch the desired keypress event.
Since AutoKey can do it, you should be able to do it too, but since
AutoKey is already doing it, that would probably complicate things.

Joe
> --
> You received this message because you are subscribed to the Google
> Groups "autokey-users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to autokey-user...@googlegroups.com
> <mailto:autokey-user...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/autokey-users/50a62e95-7262-4d4a-86ab-436405a29715%40googlegroups.com
> <https://groups.google.com/d/msgid/autokey-users/50a62e95-7262-4d4a-86ab-436405a29715%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages