The final goal is to be able to send keys where SendInput does work, but where ControlSend doesn't work. Thanks for reading.
Code: Select all
;this script works but if I reload the script
;it then ceases to work correctly
q:: ;send ctrl+c without using Send/SendInput
;e.g. tested on Notepad (Windows 7) and Internet Explorer 11
;same results, work correctly until reload
WinGet, hWnd, ID, A
ControlGetFocus, vCtlClassNN, % "ahk_id " hWnd
if !(vCtlClassNN = "")
ControlGet, hWnd, Hwnd,, % vCtlClassNN, % "ahk_id " hWnd
vTIDAhk := DllCall("kernel32\GetCurrentThreadId", "UInt")
VarSetCapacity(PBYTE1, 256, 0)
DllCall("user32\GetKeyboardState", "Ptr",&PBYTE1)
vTID := DllCall("user32\GetWindowThreadProcessId", "Ptr",hWnd, "Ptr",0, "UInt")
DllCall("user32\AttachThreadInput", "UInt",vTIDAhk, "UInt",vTID, "Int",1)
VarSetCapacity(PBYTE2, 256, 0)
NumPut(0x80, &PBYTE2, 0x11, "UChar") ;VK_CONTROL := 0x11
DllCall("user32\SetKeyboardState", "Ptr",&PBYTE2)
ControlSend,, c, % "ahk_id " hWnd
DllCall("user32\AttachThreadInput", "UInt",vTIDAhk, "UInt",vTID, "Int",0)
DllCall("user32\SetKeyboardState", "Ptr",&PBYTE1)
return
AutoHotkey source code: Send/ControlSend (modifier keys) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=26615
PostMessage plz help - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=30925