Hello, I searched on the forum before posting this, with no luck yet. This is my setup, I've got a laptop, and an external keyboard (Apple keyboard) and I was wondering if it was possible to, in one single script, detect which keyboard I'm using and set a different script. Basically, if I'm using the windows keyboard, I want to switch LAlt:LCtrl and viceversa, and if using the Apple one, I want to switch LWin::LCtrl, LAlt::LWin and LCtrl::LAlt. Right now everything is working on two different scripts, and I load the one I need manually. But I'm looking on a better solution, if there's any.
Thanks in advance guys.
Bob
Detect multiple keyboards
Re: Detect multiple keyboards
Too Easy.
Try these keywords "AHKHID", "GetRawInputDeviceList"
Good Luck
Try these keywords "AHKHID", "GetRawInputDeviceList"
Good Luck
Re: Detect multiple keyboards
Hey mate, I'm trying these examples with no luck
https://autohotkey.com/board/topic/3801 ... functions/
Some extra help would be appreciated. Thanks in advance.
https://autohotkey.com/board/topic/3801 ... functions/
Some extra help would be appreciated. Thanks in advance.
Re: Detect multiple keyboards
Try this.
I am just copy & paste it for you.
I just forgot who made this nice code.
Anyways, THANKS smart one.
It's a nice code !!!
I am just copy & paste it for you.
I just forgot who made this nice code.
Anyways, THANKS smart one.
It's a nice code !!!
Code: Select all
o := HidListObj( )
MsgBox % ""
. "You have """ o.Keyboard.MaxIndex() """ keyboard(s)"
. "`n`nThe 1st keyboard has """ o.Keyboard.1.FunctionKeys """ function keys"
. "`n`nThe name of the 1st port is """ o.Keyboard.1.Name """"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
HidListObj()
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
{
F := { Mouse:[], Keyboard:[], HID:[]}
B := {0:"Mouse", 1:"Keyboard", 2:"HID" }
DllCall( "GetRawInputDeviceList", "Ptr", 0, "UInt*", iCount, "UInt", A_PtrSize * 2)
VarSetCapacity( uHIDList, iCount * ( A_PtrSize * 2))
DllCall( "GetRawInputDeviceList", "Ptr", &uHIDList, "UInt*", iCount, "UInt", A_PtrSize * 2)
Loop % iCount
{
TypeName := b[Type:=NumGet( &uHIDList, (( A_Index - 1) * ( A_PtrSize * 2)) + A_PtrSize, "UInt")]
F[TypeName].Insert( J := [] )
J.Queue := A_Index
J.Handle := h := NumGet( &uHIDList, ( A_Index - 1) * ( A_PtrSize * 2))
DllCall( "GetRawInputDeviceInfo", "Ptr", h, "UInt", 0x20000007, "Ptr", 0, "UInt*", iLength)
VarSetCapacity( Name, ( iLength + 1) * 2)
DllCall( "GetRawInputDeviceInfo", "Ptr", h, "UInt", 0x20000007, "Str", Name, "UInt*", iLength)
J.Name := Name
DllCall( "GetRawInputDeviceInfo", "Ptr", h, "UInt", 0x2000000b, "Ptr", 0, "UInt*", iLength)
VarSetCapacity( uInfo, iLength)
NumPut( iLength, uInfo, 0, "UInt")
DllCall( "GetRawInputDeviceInfo", "Ptr", h, "UInt", 0x2000000b, "Ptr", &uInfo, "UInt*", iLength)
If ( Type = 0 )
{
J.ID := NumGet( uInfo, 8,"UInt")
J.Buttons := NumGet( uInfo, 12,"UInt")
J.SampleRate := NumGet( uInfo, 16,"UInt")
J.HWheel := NumGet( uInfo, 20,"UInt")
}
Else If ( Type = 1 )
{
J.KBType := NumGet( uInfo, 8,"UInt")
J.KBSubType := NumGet( uInfo, 12,"UInt")
J.KeyboardMode := NumGet( uInfo, 16,"UInt")
J.FunctionKeys := NumGet( uInfo, 20,"UInt")
J.Indicators := NumGet( uInfo, 24,"UInt")
J.KeysTotal := NumGet( uInfo, 28,"UInt")
}
Else If ( Type = 2 )
{
J.VendorID := NumGet( uInfo, 8,"UInt")
J.ProductID := NumGet( uInfo, 12,"UInt")
J.VersionNumber := NumGet( uInfo, 16,"UInt")
J.UsagePage := NumGet( uInfo, 20 ,"UShort")
J.Usage := NumGet( uInfo, 22, "UShort")
F[TypeName, J.Usage "_" J.UsagePage] := J
}
}
Return F
}
Re: Detect multiple keyboards
I guess you have 2 USB keyboards.
If you do not have it, I do not know what to do.
I heard the other day that the built-in Keyboard could be PS/2 type.
If it is true, I have no idea what to do.
Sorry about that.
bye.
If you do not have it, I do not know what to do.
I heard the other day that the built-in Keyboard could be PS/2 type.
If it is true, I have no idea what to do.
Sorry about that.
bye.
Re: Detect multiple keyboards
The device detection works like a charm (the one you sent), but in the examples it's not clear how to do this (meta code):
If(device == keyboard1) {
LWin::LCtrl
} else {
LAlt::LCtrl
}
I'll keep searching.
If(device == keyboard1) {
LWin::LCtrl
} else {
LAlt::LCtrl
}
I'll keep searching.
Re: Detect multiple keyboards
Think it simple.
You have two(2) boards. (B1, B2)
You have two(2) scripts. (S1, S2)
You have two(2) hotkeys. (H1, H2)
Press H1, if you are in S2 it close itself and start S1. Now, You are happy with B1.
Press H2, if you are in S1 it close itself and start S2. Now, You are happy with B2.
A_ScriptName is your good friend, in this case.
Too Easy LoL.
You have two(2) boards. (B1, B2)
You have two(2) scripts. (S1, S2)
You have two(2) hotkeys. (H1, H2)
Press H1, if you are in S2 it close itself and start S1. Now, You are happy with B1.
Press H2, if you are in S1 it close itself and start S2. Now, You are happy with B2.
A_ScriptName is your good friend, in this case.
Too Easy LoL.
Who is online
Users browsing this forum: gongnl, inseption86, jaquesy, Mannaia666, Pareidol, RussF and 148 guests