Ok, Here's what I've got so far:
Code: Select all
#NoTrayIcon
#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.
Sleep, 2000
WinActivate, ahk_class Shell_TrayWnd
Lock = 0
While ScummVM != 0
{
Process, Exist, scummvm.exe
ScummVM = %ErrorLevel%
if(GetKeyState("ctrl", "P") && GetKeyState("m", "P"))
{
Lock = 0
}
gosub, Loop
}
ExitApp
Loop:
{
#if ClickedOnWindow("ahk_exe scummvm.exe") && Lock = 0
{
~lbutton::
WinWaitActive, ahk_exe scummvm.exe
Send {Ctrl down}
Sleep, 10
Send m
Sleep, 10
Send {Ctrl up}
Lock = 1
return
}
return
}
ClickedOnWindow(wintitle)
{
local wum
mousegetpos,,,wum
if winExist(wintitle) == wum
return 1
return 0
}
return
So, this code works and does almost exactly what I want it to, however, there is a problem. The script makes two assumptions:
1. Right after the scummvm game launches, the user will first click on the window, thus locking the cursor to the window
2. The user will unlock the cursor with ctrl+m and lock by clicking on the window
If the user violates either of these assumptions, then the script gets throw off and clicking starts to unlock the cursor instead. For example, if the user decides to first press ctrl+m or if the user unlocks by pressing ctrl+m, then the script will behave incorrectly. How can I fix this?