Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I would like to be able to bind some keys to mouse clicks done in specific locations. For example: when I press F1 I should get a left mouse click at coordinates 300x350, F2 at 600x350 and so on. Even better if this could be bound to a specific window application so that coordinates could be relative to it instead of the base desktop.

Is there a software which allows this?

ADDITION:

Ok autohotkey is great but I have problems with my particular setup. Quoting my comment below:

I'm using it with an old game (championship manager 01/02) which runs in windowed mode (and I have to set win98 compatibility for it to run): I can get the mouse to move but no click goes to the application

I have read this FAQ but it didn't help, this is the script I tried:

SendMode Play
SetKeyDelay, 0, 50, Play

F1::Click 42, 191
F2::ControlSend ahk_class main, Click, Championship Manager 01/02

Still no luck: pointer moves but no click goes through.

share|improve this question

3 Answers 3

up vote 1 down vote accepted

http://www.autohotkey.com/ (and its clones) provide such feature. you want to use especially the "Click"-Command:

Clicks a mouse button at the specified coordinates. It can also hold down a mouse button, turn the mouse wheel, or move the mouse.
share|improve this answer
    
That seems perfect but I have one issue: I'm using it with an old game (championship manager 01/02) which runs in windowed mode (and I have to set win98 compatibility for it to run): I can get the mouse to move but no click goes to the application; it clicks fine in other windows. How can I fix this? –  Matteo Riva Jul 3 '10 at 8:53
SendMode Play
SetKeyDelay, 0, 0, Play

F1::Click 42, 131
F2::ControlSend ahk_class main, Click, Championship Manager 01/02
return
share|improve this answer
    
You don’t need Return for single-line hotkeys. –  Synetech Sep 18 '12 at 22:34

Coordinates are relative to the active window by default, but you can specifically set it as well. You can use different commands to achieve the app-specific behavior you want. In your case, I would recommend the # version of IfWinActive; it makes it so that the hotkeys only exist for the target window and simplifies the code.


Have you confirmed that you are accessing the correct window? Does the program’s titlebar actually say exactly Championship Manager 01/02? Try a test with a simple script to verify:

#IfWinActive, Championship Manager 01/02
  F1::MsgBox Yup; correct window.
#IfWinActive

By default, you need to match the text of the target window’s titlebar exactly, but you can use a different matching mode:

SetTitleMatchMode, 1 ; Match the start of the Window’s titlebar ; easier but more false-matches
e.g.: Championship Manager         matches

SetTitleMatchMode, 2 ; Match any part of the titlebar; easiest but most false-matches
e.g.: ship Man                     matches

SetTitleMatchMode, 3 ; Match the titlebar of the Window exactly; most restrictive but fewer false-matches
e.g.: Championship Manager 01/02   matches


There are numerous ways to emulate a mouse-click. Try each one until you find one that works for your program. You can specify the mode for the Click command and the generic Send command (which default to Event), or you can specify the mode explicitly (Play is recommended for stubborn programs and games):

Send      Click 42,191   ; defaults to Event
SendPlay  Click 42,191
SendInput Click 42,191
SendEvent Click 42,191

SendMode  Input
Send      Click 42,191   ; uses Input mode
SendMode  Play
Send      Click 42,191   ; uses Play mode
SendMode  Event
Send      Click 42,191   ; back to Event mode


Instead of sending a mouse-click, you could try sending a left-mouse-button, but first you need to move the cursor manually:

MouseMove 42,191,0 ; Immediately move the cursor relative to the active window
Send LButton       ; Left-click


As for ControlSend, note that it specifically says:

Unlike the Send command, mouse clicks cannot be sent by ControlSend. Use ControlClick for that.

ControlClick isn’t really meant for sending clicks to a top-level window, so you would have to identify the control(s), and this assumes that the game even uses actual controls.


Try the following and change the SendMode if necessary (particularly try Play)

CoordMode, Mouse, Relative           ; Explicitly set mouse coords to relative
SetTitleMatchMode, 1                 ; Match start of titlebar (e.g., Foobar*)
SendMode Event                       ; Use Event mode (try Input and Play)
#IfWinActive, Championship Manager   ; Only make hotkeys for specified window
  F1::Click 42, 191                  ;  Send a mouse-click (left-click)
  F2::Click 558, 191                 ;  …
#IfWinActive                         ; Reset conditional block
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.