One of user of this forum created for me script which can recognize keyboard when is pressed key, here's code:
Code: Select all
#NoEnv
SetBatchLines -1
OnMessage(0xFF, "InputHandler")
RegisterRawInputDevices(1, 6)
Esc::ExitApp
InputHandler(wParam, lParam) {
static RID_INPUT := 0x10000003
static RIDI_DEVICENAME := 0x20000007
Critical
DllCall("GetRawInputData"
, "Ptr", lParam
, "UInt", RID_INPUT
, "Ptr", 0
, "UIntP", size
, "UInt", 8 + A_PtrSize * 2)
VarSetCapacity(buffer, size)
DllCall("GetRawInputData"
, "Ptr", lParam
, "UInt", RID_INPUT
, "Ptr", &buffer
, "UIntP", size
, "UInt", 8 + A_PtrSize * 2)
devHandle := NumGet(buffer, 8)
SetFormat, IntegerFast, hex
vk := NumGet(buffer, 8 + 2 * A_PtrSize + 6, "UShort")
sc := NumGet(buffer, 08+A_PtrSize*2, "UShort")
flg := NumGet(buffer, 10+A_PtrSize*2, "UShort")
vky := StrGet (vk)
scy := StrGet (sc)
SetFormat, Integer, d
StringTrimLeft, vkx, vky, 2
StringTrimLeft, scx, scy, 2
if StrLen(scx) = 2
{
scx := "0" . scx
}
else if StrLen(scx) = 1
{
scx := "00" . scx
}
klaves := "vk" . vkx . "sc" . scx
KeyLen := StrLen(klaves)
DllCall("GetRawInputDeviceInfo"
, "Ptr", devHandle
, "UInt", RIDI_DEVICENAME
, "Ptr", 0
, "UIntP", size)
VarSetCapacity(info, size)
DllCall("GetRawInputDeviceInfo"
, "Ptr", devHandle
, "UInt", RIDI_DEVICENAME
, "Ptr", &info
, "UIntP", size)
GotInfo := StrGet(&info)
StringMid, GotID, GotInfo, 13 , 3
if GotID =1A2
{
KB =Inland
}
Else if GotID = 030
{
KB =Adesso
}
Else if GotID =05A
{
KB =Wireless DELL
}
Else if GotID =04F
{
KB =Japanese
}
Else if GotID =1C4
{
KB =Keypad
}
Else if GotID =E0F
{
KB =Genesis Mouse
}
Else
{
KB = %GotInfo%
KBID = %GotID%
}
ToolTip % "`keyboard:`t" KB
. "`ndevice ID:`t" GotID
. "`nscancode vk:`t" vk
. "`nscancode sc:`t" sc
. "`nflags:`t" flg
. "`nkeycode:`t`t" klaves
. "`nCodeLen:`t" KeyLensdds
. "`npressed:`t`t" A_TickCount
klaves := ""
KeyLen := 0
vky := ""
vkx := ""
scy := ""
scx := ""
}
RegisterRawInputDevices(usagePage, usage) {
static RIDEV_INPUTSINK := 0x00000100
VarSetCapacity(rawDevice, 8 + A_PtrSize)
NumPut(usagePage, rawDevice, 0, "UShort")
NumPut(usage, rawDevice, 2, "UShort")
NumPut(RIDEV_INPUTSINK, rawDevice, 4, "UInt")
NumPut(A_ScriptHWND, rawDevice, 8, "UPtr")
if !DllCall("RegisterRawInputDevices"
, "Ptr", &rawDevice
, "UInt", 1
, "UInt", 8 + A_PtrSize)
{
throw "Fail"
}
}
Code: Select all
#SingleInstance force
#NoEnv
SetBatchLines -1
OnMessage(0xFF, "InputHandler")
RegisterRawInputDevices(1, 6)
Esc::ExitApp
InputHandler(wParam, lParam) {
static RID_INPUT := 0x10000003
static RIDI_DEVICENAME := 0x20000007
Critical
DllCall("GetRawInputData"
, "Ptr", lParam
, "UInt", RID_INPUT
, "Ptr", 0
, "UIntP", size
, "UInt", 8 + A_PtrSize * 2)
VarSetCapacity(buffer, size)
DllCall("GetRawInputData"
, "Ptr", lParam
, "UInt", RID_INPUT
, "Ptr", &buffer
, "UIntP", size
, "UInt", 8 + A_PtrSize * 2)
devHandle := NumGet(buffer, 8)
SetFormat, IntegerFast, hex
vk := NumGet(buffer, 8 + 2 * A_PtrSize + 6, "UShort")
sc := NumGet(buffer, 08+A_PtrSize*2, "UShort")
flg := NumGet(buffer, 10+A_PtrSize*2, "UShort")
vky := StrGet (vk)
scy := StrGet (sc)
SetFormat, Integer, d
StringTrimLeft, vkx, vky, 2
StringTrimLeft, scx, scy, 2
if StrLen(scx) = 2
{
scx := "0" . scx
}
else if StrLen(scx) = 1
{
scx := "00" . scx
}
klaves := "vk" . vkx . "sc" . scx
KeyLen := StrLen(klaves)
DllCall("GetRawInputDeviceInfo"
, "Ptr", devHandle
, "UInt", RIDI_DEVICENAME
, "Ptr", 0
, "UIntP", size)
VarSetCapacity(info, size)
DllCall("GetRawInputDeviceInfo"
, "Ptr", devHandle
, "UInt", RIDI_DEVICENAME
, "Ptr", &info
, "UIntP", size)
GotInfo := StrGet(&info)
StringMid, GotID, GotInfo, 13 , 3
if GotID =1A2
{
KB =Inland
}
Else if GotID = 030 ; 1C4 = used before
{
KB =Adesso
}
Else if GotID =05A
{
KB =Wireless
}
Else if GotID =04F
{
KB =Japanese
}
Else if GotID =13B
{
KB =Dell PS/2
}
Else if GotID =1C4
{
KB =Keypad
}
Else
{
KB = %GotInfo%
KBID = %GotID%
}
RegisterRawInputDevices(usagePage, usage) {
static RIDEV_INPUTSINK := 0x00000100
VarSetCapacity(rawDevice, 8 + A_PtrSize)
NumPut(usagePage, rawDevice, 0, "UShort")
NumPut(usage, rawDevice, 2, "UShort")
NumPut(RIDEV_INPUTSINK, rawDevice, 4, "UInt")
NumPut(A_ScriptHWND, rawDevice, 8, "UPtr")
if !DllCall("RegisterRawInputDevices"
, "Ptr", &rawDevice
, "UInt", 1
, "UInt", 8 + A_PtrSize)
{
throw "Fail"
}
}
; ==== EXAMPLE ====
If klaves=SC029 ; compare to keys
{
Send, {Raw};
return
}
else If klaves=SC002 ; compare to keys
{
Send, {Raw}~
return
}
Error at line 94.
Line text: RegisterRawInputDevices(usagePage, usage)
Error: Functions cannot contain functions.
The program will exit.
Really I did only one simple thing - pasted original code to script.
Modified scripts works not.
Can anybody help me why it works not?
Thank you for all.
Miro