Created
October 19, 2020 12:38
-
-
Save JoeGlines/76f040140e78c97bf841d9f0eccc32d7 to your computer and use it in GitHub Desktop.
Configure the Zoom key to do a page up / page down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;~ https://autohotkey.com/board/topic/36304-hidextended-input-devices-ms-natural-keyboard-4000-etc/page-2 | |
; Capture input from the "Zoom" slider on the Natural Keyboard 4000 and use it to scroll up and scroll down | |
; The HID top level collection for the Natural Keyboard 4000 is:; Usage 1 ; Usage Page 12 | |
;~ #NoTrayIcon | |
#SingleInstance force ; Replace any previous instance | |
DetectHiddenWindows, on | |
OnMessage(0x00FF, "InputMessage") | |
SizeofRawInputDeviceList := 8, SizeofRidDeviceInfo := 32, RIM_TYPEMOUSE := 0, RIM_TYPEKEYBOARD := 1, RIM_TYPEHID := 2, RIDI_DEVICENAME := 0x20000007 | |
RIDI_DEVICEINFO := 0x2000000b, RIDEV_INPUTSINK := 0x00000100, RID_INPUT := 0x10000003, Usage := 1, UsagePage := 12 | |
Gui, Show, Hide, NaturalCapture | |
HWND := WinExist("NaturalCapture") | |
; Keyboards are always Usage 6, Usage Page 1, Mice are Usage 2, Usage Page 1, HID devices specify their top level collection in the info block | |
VarSetCapacity(RawDevice, 12),NumPut(RIDEV_INPUTSINK, RawDevice, 4),NumPut(HWND, RawDevice, 8),NumPut(UsagePage, RawDevice, 0, "UShort"),NumPut(Usage, RawDevice, 2, "UShort") | |
Res := DllCall("RegisterRawInputDevices", "UInt", &RawDevice, UInt, 1, UInt, 12) | |
if (Res = 0) | |
MsgBox, Failed to register for Natural Keyboard | |
InputMessage(wParam, lParam, msg, hwnd){ | |
global DoCapture, RIM_TYPEMOUSE, RIM_TYPEKEYBOARD, RIM_TYPEHID, RID_INPUT | |
if (DoCapture = 0) | |
return | |
Res := DllCall("GetRawInputData", UInt, lParam, UInt, RID_INPUT, UInt, 0, "UInt *", Size, UInt, 16),VarSetCapacity(Buffer, Size) | |
Res := DllCall("GetRawInputData", UInt, lParam, UInt, RID_INPUT, UInt, &Buffer, "UInt *", Size, UInt, 16) | |
Type := NumGet(Buffer, 0 * 4),Size := NumGet(Buffer, 1 * 4), Handle := NumGet(Buffer, 2 * 4) | |
if (Type = RIM_TYPEHID){ | |
SizeHid := NumGet(Buffer, (16 + 0)),InputCount := NumGet(Buffer, (16 + 4)) | |
Loop %InputCount% { | |
Addr := &Buffer + 24 + ((A_Index - 1) * SizeHid), BAddr := &Buffer ,Input := Mem2Hex(Addr, SizeHid) | |
if (IsLabel(Input)) | |
Gosub, %Input% | |
} | |
} | |
return | |
} | |
return | |
DoScroll: | |
ControlGetFocus, fcontrol, A ; WM_VSCROLL = 0x115, SB_LINEUP = 0, SB_LINEDOWN = 1 | |
;********************What to do...*********************************** | |
if (ScrollDir = 1) { ;If zoom is up | |
Send {PgUp} ;Scrolling up | |
}else{ ;If Zoom is down | |
Send {PgDn} ;Scrolling down | |
} | |
Return | |
012E020000010000: ; Zoom down | |
ScrollDir := 2 | |
GoSub, DoScroll | |
SetTimer, DoScroll, 1080 | |
return | |
012D020000010000: ; Zoom up | |
ScrollDir := 1 | |
GoSub, DoScroll | |
SetTimer, DoScroll, 1080 | |
return | |
0100000000010000: ; All up | |
ScrollDir := 0 | |
SetTimer, DoScroll, Off | |
return | |
Mem2Hex( pointer, len ){ | |
A_FI := A_FormatInteger | |
SetFormat, Integer, Hex | |
Loop, %len% { | |
Hex := *Pointer+0 | |
StringReplace, Hex, Hex, 0x, 0x0 | |
StringRight Hex, Hex, 2 | |
hexDump := hexDump . hex | |
Pointer ++ | |
} | |
SetFormat, Integer, %A_FI% | |
StringUpper, hexDump, hexDump | |
Return hexDump | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment