Is there any way programmatically to detect the Keyboard Type/Keyboard name? The reason is, I am often switching keyboards and computers, yet I would like to have only 1 .ahk script.
Can AHK fetch the keyboard name from the device manager or so?
Detecting keyboard type/device name
Re: Detecting keyboard type/device name
Do you see the name of the keyboard somewhere? (in the device manager?)
Maybe this give you all devices?
For this you need AHK + COM Standard Library:
Maybe this give you all devices?
Code: Select all
; Enumerate Query
for device in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_PnPEntity")
list .= device.name "`n"
MsgBox, %list%
Code: Select all
COM_Init()
; Create Query
wmi := COM_GetObject("winmgmts:")
Query := COM_Invoke(wmi, "ExecQuery", "Select * from Win32_PnPEntity")
enumQuery := COM_Invoke(Query, "_NewEnum")
; Enumerate Query
while COM_Enumerate(enumQuery, device)=0
list .= COM_Invoke(device, "Name") "`n"
MsgBox, %list%
COM_Release(wmi), COM_Release(Query), COM_Release(enumQuery), COM_Term()
Re: Detecting keyboard type/device name
Yes, this works Is there a way to list Keyboards only instead of all PnP devices?Albireo wrote: ↑28 May 2020, 17:54Do you see the name of the keyboard somewhere? (in the device manager?)
Maybe this give you all devices?
Code: Select all
; Enumerate Query for device in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_PnPEntity") list .= device.name "`n" MsgBox, %list%
Re: Detecting keyboard type/device name
Maybe this code is better for you? (change USB to something you search for)
The choices for Win32_PnPEntity I could find are on this page Device Management Reference and more specific Win32_PnPEntity class From this I have tried ".name" and ".manufacturer" (Have no idea what other of these choices can provide something.)
EDIT:
(Have no idea what this is - maybe something for you?)
DeviceInterfaces.ahk
Code: Select all
for device in ComObjGet("winmgmts:").ExecQuery("Select * from Win32_PnPEntity")
{
If InStr(device.manufacturer, "USB" )
list .= device.name "`t`t`t" device.manufacturer "`n"
}
MsgBox, %list%
EDIT:
(Have no idea what this is - maybe something for you?)
DeviceInterfaces.ahk
Re: Detecting keyboard type/device name
Thank you very much for your help. That's a huge script and I am not sure it would run on a non-elevated account. The script you posted works fineAlbireo wrote: ↑29 May 2020, 17:08(Have no idea what this is - maybe something for you?)
DeviceInterfaces.ahk
Re: Detecting keyboard type/device name
FYI DeviceInterfaces.ahk url changed, also requires EnumDeviceInterfaceClasses which is currently AWOL.
itros "ylbbub eht tuO kaerB" a ni kcuts m'I pleH