Skip to content

Commit

Permalink
XmgFusion15: No longer use AutoHotInterception as the driver limitati…
Browse files Browse the repository at this point in the history
…ons are just stupid
  • Loading branch information
TheBestPessimist committed Jun 27, 2022
1 parent e5edc61 commit b834a1f
Showing 1 changed file with 56 additions and 21 deletions.
77 changes: 56 additions & 21 deletions XmgFusion15.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ XmgFusion15AutoExecute()

static autoExecute := XmgFusion15AutoExecute()

changeKeyOrder()
; changeKeyOrderUsingAutoHotInterception()

changeKeyOrderByDetectingUSBKeyboard()

}


Expand All @@ -34,27 +37,67 @@ XmgFusion15AutoExecute()
; and not the keys from other connected keyboards
;
; PROBLEM: this doesn't always block the original key therefore I have to use "subscription" mechanism instead of the easier to use "context"
changeKeyOrder()
; changeKeyOrderUsingAutoHotInterception()
; {
; AHI := new AutoHotInterception()
; Fusion15KeyboardId := AHI.GetKeyboardIdFromHandle("ACPI\VEN_MSFT&DEV_0001", 1)
;
; AHI.SubscribeKey(Fusion15KeyboardId, GetKeySC("PgUp"), true, Func("XmgKeyEventHandler").Bind("PgDn"))
; AHI.SubscribeKey(Fusion15KeyboardId, GetKeySC("PgDn"), true, Func("XmgKeyEventHandler").Bind("Home"))
; AHI.SubscribeKey(Fusion15KeyboardId, GetKeySC("Home"), true, Func("XmgKeyEventHandler").Bind("PgUp"))
;
; Tippy("inside changeKeyOrder")
; }
;
; XmgKeyEventHandler(newKey, state)
; {
; if(state)
; Send % "{Blind}{" newKey " down}"
; else
; Send % "{Blind}{" newKey " up}"
; }


; The thing above is commented out, because Interception driver is fucked and after disconnecting and reconnecting ANY USB device multiple times,
; all usb devices stop working.
; Source: https://www.autohotkey.com/boards/viewtopic.php?f=76&p=439480
changeKeyOrderByDetectingUSBKeyboard()
{
AHI := new AutoHotInterception()
Fusion15KeyboardId := AHI.GetKeyboardIdFromHandle("ACPI\VEN_MSFT&DEV_0001", 1)

AHI.SubscribeKey(Fusion15KeyboardId, GetKeySC("PgUp"), true, Func("XmgKeyEventHandler").Bind("PgDn"))
AHI.SubscribeKey(Fusion15KeyboardId, GetKeySC("PgDn"), true, Func("XmgKeyEventHandler").Bind("Home"))
AHI.SubscribeKey(Fusion15KeyboardId, GetKeySC("Home"), true, Func("XmgKeyEventHandler").Bind("PgUp"))
OnMessage(0x219, "onUsbDeviceChangeTimer")
}

Tippy("inside changeKeyOrder")
onUsbDeviceChangeTimer()
{
SetTimer % "onUsbDeviceChange", -2000
}

XmgKeyEventHandler(newKey, state)
global usbKeyboardAttached := false
onUsbDeviceChange()
{
if(state)
Send % "{Blind}{" newKey " down}"
global usbKeyboardAttached
static corsairKeyboardDeviceId := "HID\VID_1B1C&PID_1B13&MI_00&COL01\8&270545BF&0&0000"

saveClipboard()

PS := "Get-WmiObject Win32_PNPEntity | Sort-Object -Property DeviceID | Format-Table DeviceID | clip"
RunWait, PowerShell.exe -Command "%PS%",, Hide
found := InStr(Clipboard, corsairKeyboardDeviceId)
if found
usbKeyboardAttached := true
else
Send % "{Blind}{" newKey " up}"
usbKeyboardAttached := false

restoreClipboard()
}


#If !usbKeyboardAttached
{
PgUp::PgDn
PgDn::Home
Home::PgUp
}
#if



Expand Down Expand Up @@ -104,15 +147,7 @@ sc178 & 9::NumPad9
;sc178 & F5::return



; ====
; ==== Fn Lock
;
; still todo


; ====
; ==== Disable insert key
;

Insert::Return

0 comments on commit b834a1f

Please sign in to comment.