I found this:
https://autohotkey.com/board/topic/3801 ... ntry251836
and tried to implement it but ran into some very strange issues.
The demo code below should block the "c" when pressed and output "Logitech_c" if the key was pressed on a Logitech keyboard and "other_c" if it was pressed on any other keyboard independent in which application.
What I see is:
1. The behaviour depends on if I press "c" in the AHK Gui edit field or any other application:
- in AHK the "c" is not blocked, so I get both the original "c" and the output of the SendInput; the hotkey seems to be not working
- in any other application the "c" is blocked but also no WM_INPUT message is generated so that I get no output at all from pressing "c"
2. The Shift pressed by SendInput for the capital L and the underscore is stuck afterwards until manually pressed, so I get e.g. "cLOGITECH_C" instead of the expected "Logitech_c" as output in the AHK window
The problem seems to be the combination of the keyboard-hook hotkey $c:: and the RawInput handling from AHKHID. When I remove either one the script behaves as would be expected in that case. I tried this on Win10 with the latest AHK version but it also seems to occur on Win7 with an older 1.1.23 AHK version. It is also not necessary to have two keyboards connected to verify the behaviour.
I'm stuck... Is there anything I'm doing wrong? Is it a bug in AHK or somewhere else? Is there any way to work around this without installing other software?
Any help would be appreciated.
My example code:
Code: Select all
#Include AHKHID.ahk
;Create GUI
Gui +LastFound -Resize -MaximizeBox -MinimizeBox
Gui, Add, Edit, w1500 r15 vtxtres,
Gui, Add, Edit, w1500 r15 vtxtlst,
;Keep handle
GuiHandle := WinExist()
;Set up the constants
AHKHID_UseConstants()
; get keyboard events from all applications
AHKHID_Register(1, 6, GuiHandle, RIDEV_INPUTSINK)
;Intercept WM_INPUT
OnMessage(0x00FF, "InputMsg")
; enable next line to demonstrate that shift gets stuck in SendInput
;~ Settimer, timer1, 2000
;Show GUI
Gui, Show
Return
GuiClose:
ExitApp
$c:: Return ; block c
InputMsg(wParam, lParam) {
Local r, h
critical ;Or otherwise you could get ERROR_INVALID_HANDLE
;Get device type
r := AHKHID_GetInputInfo(lParam, II_DEVTYPE)
If (r = RIM_TYPEKEYBOARD)
{
h := AHKHID_GetInputInfo(lParam, II_DEVHANDLE)
lstvar.="`r`n"
. " MakeCode: " AHKHID_GetInputInfo(lParam, II_KBD_MAKECODE)
. " Flags: " AHKHID_GetInputInfo(lParam, II_KBD_FLAGS)
. " VKey: " AHKHID_GetInputInfo(lParam, II_KBD_VKEY)
. " Message: " AHKHID_GetInputInfo(lParam, II_KBD_MSG)
. " ExtraInfo: " AHKHID_GetInputInfo(lParam, II_KBD_EXTRAINFO)
. " Name: " AHKHID_GetDevName(H, True)
GuiControl,, txtlst, % lstvar
; is it a c-down event?
If (AHKHID_GetInputInfo(lParam, II_KBD_FLAGS)=0 and AHKHID_GetInputInfo(lParam, II_KBD_VKEY)=67)
{
If (Instr(AHKHID_GetDevName(H, True),"HID#VID_046D")) ; is it a Logitech device?
{
SetTimer, timer1, -1
}
Else If (AHKHID_GetDevName(H, True)<>"") ; make sure it's from another real device
{
SetTimer, timer2, -1
}
}
}
return, 0
}
timer1:
SendInput Logitech_c
return
timer2:
SendInput Other_c
return