Kuklakot you are my hero
I don't like using up and down as scrolling though so here is my take on it (plus a few hotkeys and different keycodes)
Code:
; 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
; Replace any previous instance
#SingleInstance force
C(str) ; const container
{
return, (%str%)
static MS_SHORT := 2
static MS_DWORD := 4
static MS_PTR := 8 ;x64 specific
static SizeofRawInputDevice := MS_SHORT*2 + MS_DWORD + MS_PTR
/*
typedef struct tagRAWINPUTDEVICE {
USHORT usUsagePage;
USHORT usUsage;
DWORD dwFlags;
HWND hwndTarget;
} RAWINPUTDEVICE, *PRAWINPUTDEVICE, *LPRAWINPUTDEVICE;
*/
static SizeofRawInputDataHeader := MS_DWORD*2 + MS_PTR*2
/*
typedef struct tagRAWINPUTHEADER {
DWORD dwType;
DWORD dwSize;
HANDLE hDevice;
WPARAM wParam;
} RAWINPUTHEADER, *PRAWINPUTHEADER;
*/
static RIM_TYPEMOUSE := 0
static RIM_TYPEKEYBOARD := 1
static RIM_TYPEHID := 2
static RIDI_DEVICENAME := 0x20000007
static RIDI_DEVICEINFO := 0x2000000b
static RIDEV_INPUTSINK := 0x00000100 ; receive in foreground
static RID_INPUT := 0x10000003 ; request header
; 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
static Usage := 1
static UsagePage := 12
}
HID_Input_Init:
{
DetectHiddenWindows, on
OnMessage(0x00FF, "InputMessage")
Gui, Show, Hide, NaturalCapture
HWND := WinExist("NaturalCapture")
VarSetCapacity(RawInputDevice, C("SizeofRawInputDevice"))
NumPut(C("UsagePage"), RawInputDevice, 0)
NumPut(C("Usage"), RawInputDevice, C("MS_SHORT"))
NumPut(C("RIDEV_INPUTSINK"), RawInputDevice, C("MS_SHORT")*2)
NumPut(HWND, RawInputDevice, C("MS_SHORT")*2 + C("MS_DWORD"))
Res := DllCall("RegisterRawInputDevices", "UInt", &RawInputDevice, UInt, 1, UInt, C("SizeofRawInputDevice"))
if (Res = 0)
MsgBox, Failed to register for Natural Keyboard
return
}
InputMessage(wParam, lParam, msg, hwnd)
{
Res := DllCall("GetRawInputData", UInt, lParam, UInt, C("RID_INPUT"), UInt, 0, "UInt *", Size, UInt, C("SizeofRawInputDataHeader"))
VarSetCapacity(RawInputData, Size)
Res := DllCall("GetRawInputData", UInt, lParam, UInt, C("RID_INPUT"), UInt, &RawInputData, "UInt *", Size, UInt, C("SizeofRawInputDataHeader"))
SetFormat, Integer, Hex
Type := NumGet(RawInputData, 0, "UInt")
Size := NumGet(RawInputData, 1 * C("MS_DWORD"), "UInt")
Handle := NumGet(RawInputData, 2 * C("MS_DWORD"), "UInt64") ; x64 specific
if (Type = C("RIM_TYPEHID"))
{
SizeHid := NumGet(RawInputData, (C("SizeofRawInputDataHeader") + 0), "UInt")
InputCount := NumGet(RawInputData, (C("SizeofRawInputDataHeader") + C("MS_DWORD")), "UInt")
Loop %InputCount% {
Addr := &RawInputData + C("SizeofRawInputDataHeader") + C("MS_DWORD")*2 + ((A_Index - 1) * SizeHid)
BAddr := &RawInputData
Input := Mem2Hex(Addr, SizeHid)
;MsgBox, %Input%
/*
if (Input != 0100000000010000 && Input != 0100000000000000)
{
SoundPlay, *64
clipboard = %clipboard%`r`n%Input%
}
*/
if (IsLabel(Input))
Gosub, %Input%
}
}
else
return
}
; 1 = UP, 2 = DOWN
ScrollDir := 0
DoScroll:
ControlGetFocus, fcontrol, A
; WM_VSCROLL = 0x115, SB_LINEUP = 0, SB_LINEDOWN = 1
Loop 1
{
if (ScrollDir = 1)
SendInput, {WheelUp}
else
SendInput, {WheelDown}
}
Return
; // Special Keys //
; ++ Function Keys ++
; Function Key "="
0100006700000000:
Send {=}
return
; Function Key "("
010000B600000000:
Send {(}
return
; Function Key ")"
010000B700000000:
Send {)}
return
; ++ Favorites Keys ++
; Favorites 1
0100000000040000:
Send {)}
return
; Favorites 2
0100000000080000:
Send {)}
return
; Favorites 3
0100000000100000:
Send {)}
return
; Favorites 4
0100000000200000:
Send {)}
return
; Favorites 5
0100000000400000:
Run "C:\Program Files\uTorrent\utorrent.exe"
return
; My Favorites
0182010000000000:
Run "C:\Program Files\uTorrent\utorrent.exe"
return
; ++ Media Keys ++
; Play/Pause
01CD000000000000:
If WinExist("ahk_class XMPLAY-MAIN")
ControlSend, , {Media_Play_Pause}, ahk_class XMPLAY-MAIN
else
{
Run "D:\Archiwum\Programy\Inne\Music Players\XMPlay\XMPlay.exe"
while !(WinExist("ahk_class XMPLAY-MAIN"))
Sleep 333
Sleep 999
ControlSend, , {Media_Play_Pause}, ahk_class XMPLAY-MAIN
}
return
; Calculator
0192010000000000:
Run "D:\Archiwum\Programy\System\Narzedzia\Windows7-calculator\Calc.exe"
return
; ++ Zoom/Scroll Keys ++
; Zoom Down
012E020000000000:
ScrollDir := 2
GoSub, DoScroll
SetTimer, DoScroll, 80
return
; Zoom Up
012D020000000000:
ScrollDir := 1
GoSub, DoScroll
SetTimer, DoScroll, 80
return
; All up
0100000000000000:
ScrollDir := 0
SetTimer, DoScroll, Off
return
; ++ Standard Special Keys ++
Launch_Mail::Run "C:\Program Files (x86)\Mozilla\Thunderbird\thunderbird.exe"
Browser_Search::Run "C:\Program Files (x86)\Avira\AntiVir Desktop\avscan.exe" /GUIMODE=1 /PATH="c:\"
Browser_Home::DllCall("PowrProf\SetSuspendState", "int", 0, "int", 1, "int", 0)
; // Combinations //
^PgUp::ControlSend, , ^{PgUp}, ahk_class XMPLAY-MAIN
^PgDn::ControlSend, , ^{PgDn}, ahk_class XMPLAY-MAIN
^End::ControlSend, , ^{End}, ahk_class XMPLAY-MAIN
; // Buttons Customized for Applications //
if (InStr(ClassName, "Mozilla") or InStr(ClassName, "Opera"))
Browser_Forward::^Right
Debug(msg)
{
OutputDebug, %msg%
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
}