So, if i'm in autocad, and i click the xbutton2, it just either set the focus on the calculator, or, if it's not open, it should.
"Rekenmachine" is dutch for calculator, and is the name of the window:
from window spy:
Rekenmachine
ahk_class ApplicationFrameWindow
ahk_exe ApplicationFrameHost.exe
ahk_pid 10360
ahk_id 659352
Code: Select all
#NoEnv
SetWorkingDir %A_ScriptDir%
CoordMode, Mouse, Window
SendMode Input
#SingleInstance Force
SetTitleMatchMode 2
SetTitleMatchMode Fast
#WinActivateForce
SetControlDelay 1
SetWinDelay -1
SetKeyDelay -1
SetMouseDelay -1
SetBatchLines -1
#if WinActive("ahk_exe acad.exe")
XButton2::
Send, {u}
Sleep, 15
Send, {c}
Sleep, 15
Send, {s}
Sleep, 15
Send, {Space}
Return
XButton1::
If (WinExist ("Rekenmachine"))
{
WinActivate ("Rekenmachine")
}
Else
{
Run, "C:\Windows\WinSxS\wow64_microsoft-windows-calc_31bf3856ad364e35_10.0.19041.1_none_6a03b910ee7a4073\Calc.exe"
}
Return
#If