1
votes

PREVIOUS QUESTION: I'm playing an online flash game that is basically Hangman. The only way to input letters is by clicking on them on the on-screen keyboard in the game. I'd like to write some sort of macro that would map keyboard presses with mouse locations, so that I could type the letters on my keyboard and have the mouse go click on the corresponding on-screen keyboard letters. I'm running Windows 7 on a Dell laptop. Is there any way to do this? Any programs that would help with this? I have some experience programming in Java if that helps.

UPDATE: I'm using AutoHotKey to write the macro. Here is what I have:

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
LAlt & a::
IfWinExist Bearville - Mozilla Firefox
{
    WinActivate
}
DllCall("mouse_event", "UInt", 0x01, "UInt", 460, "UInt", 560) ; move 
DllCall("mouse_event", "UInt", 0x02) ; left button down
DllCall("mouse_event", "UInt", 0x04) ; left button up
sleep 250
DllCall("mouse_event", "UInt", 0x01, "UInt", -460, "UInt", -560) ; move 
return
LAlt & b::
IfWinExist Bearville - Mozilla Firefox
{
    WinActivate
}
DllCall("mouse_event", "UInt", 0x01, "UInt", 500, "UInt", 560) ; move 
DllCall("mouse_event", "UInt", 0x02) ; left button down
DllCall("mouse_event", "UInt", 0x04) ; left button up
sleep 250
DllCall("mouse_event", "UInt", 0x01, "UInt", -500, "UInt", -560) ; move 
return

and so on. If the window is not active, activate it. Move the pointer from the upper left corner to the location of the letter on the screen, left mouse button down and up, wait 250 milliseconds (because having no delay resulted in the click not registering) and then move the pointer back to the starting location. This works for one letter, but if I try to enter another letter right afterwards, the window loses focus as soon as I press the left alt key. Finishing entering the hotkey makes the window activate but the pointer does not seem to move or click, and the window loses focus again. How can I fix it?

2

2 Answers

0
votes

If the virtual keyboard has a fixed position, you can use this...

a::MouseClick, left, 150,150
b::MouseClick, left, 250,250

Just use autoHotKey Window Spy to find the exact mouse coordinates. you will need to do this 26 times though, but it is easy and straight forward and should not cause any loss of focus problems.

0
votes

If there is a reason you are using DllCalls instead of send, this might not work, but what I would do for this type of application is write a hotkey that starts a loop until another hotkey is pressed, and then use input to listen for any typed characters to click on.

Something like this:

LAlt & a::
IfWinExist Bearville - Mozilla Firefox
{
    WinActivate
}
flag = 1
while flag
{
    Input, inval, B L1, {Space}
    IfInString, errorlevel, EndKey
    {
        flag = 0
    } else {
        x, y = locationForChar(inval)
        ;I'd reccomened a switch or if statement chain
        Send {Click %x%, %y%}
    }
}

This should start reading all input after the 'LAlt & a' hotkey is pressed, and will terminate after the space key is pressed.