Page 1 of 1

Griffin Powermate (USB) AHKHID script

Posted: 19 Jun 2018, 18:03
by Stevie
Here's my script to control the Griffin Powermate. This enables you to get rid of the official (unsupported) Powermate software.
Per default, only left and right turn are assigned (mousewheel up and down), but you can easily add the other functions as well (button press, button press + turn left, button press + turn right.
Additionally you can also use modifiers (which is not possible with the official software). So you can use CTRL + Powermate turn left, etc...
And last but not least, you could also create different assignments, depending on which window has focus.

The only thing you can't configure: the LED.

Code: Select all

SetWorkingDir %A_ScriptDir%
#include ahkhid.ahk
#InstallKeybdHook ;install keyboard hook, enables you to use modifier keys in conjunction with the Powermate

Gui, +LastFound
GuiH := WinExist()

;Intercept WM_INPUT messages
WM_INPUT := 0xFF
OnMessage(WM_INPUT, "InputMsg")

AHKHID_Register(12, 1,GuiH, RIDEV_INPUTSINK) ;register device

InputMsg(wParam, lParam) 
{
    Local devh, key
    Critical    ;or otherwise you could get ERROR_INVALID_HANDLE

	;get handle of device
    devh := AHKHID_GetInputInfo(lParam, II_DEVHANDLE)

	If (devh <> -1)
        And (AHKHID_GetDevInfo(devh, DI_DEVTYPE, True) = RIM_TYPEHID)
        And (AHKHID_GetDevInfo(devh, DI_HID_VENDORID, True) = 1917) ;Replace these three
        And (AHKHID_GetDevInfo(devh, DI_HID_PRODUCTID, True) = 1040) ;numbers with your
        And (AHKHID_GetDevInfo(devh, DI_HID_VERSIONNUMBER, True) = 8) ;devices numbers.
        {

	;get the keycode
	key := (AHKHID_GetInputInfo(lParam, II_MSE_RAWBUTTONS))
	
    If (key == 16711680) ; turn Powermate left
		SendInput {WheelDown} ;send mousewheel down
	
	If (key == 65536) ; turn Powermate right
		SendInput {WheelUp} ;send mousewheel up
	
	;If (key == 256) ; press button
		;assign your own action
		
	;If (key == 16711936) ; press button + turn Powermate left
		;assign your own action
		
	;If (key == 65792) ; press button + turn Powermate right
		;assign your own action
	}

}

Re: Griffin Powermate AHKHID script

Posted: 19 Jun 2018, 18:26
by Xtra
Could you please post/link which model of Griffin Powermate you are using (Im going to assume the bluetooth model wouldnt work?) and maybe a source link to the ahkhid.ahk.

Thanks

Re: Griffin Powermate (USB) AHKHID script

Posted: 19 Jun 2018, 18:40
by Stevie
Hey Xtra,

I'm indeed using the USB version of the Powermate. Unfortunately, I cannot say, if this will work with the bluetooth version.
However, you can try it first. Maybe it does work. And if not, there are ways to get this working ;)

That's the AHKHID.ahk I'm using:
AHKHID.ahk
(28.95 KiB) Downloaded 261 times

Re: Griffin Powermate (USB) AHKHID script

Posted: 20 Jun 2018, 08:39
by evilC
Would be interested to know if you can use AutoHotInterception with this device (See link in sig)
Are the codes (16711680, 65536) normal key scancodes or custom codes?

Re: Griffin Powermate (USB) AHKHID script

Posted: 29 Jun 2018, 20:59
by Stevie
That's a good question. To find out what codes are sent, I used this script. I'm not really sure, if these are scan codes.
They looked strange to me :P
SetWorkingDir %A_ScriptDir%
#include ahkhid.ahk

Gui,Add,Text,,Click and hold additional mouse button with this window active`nTake notice of numbers in tooltip`nNote them as they change when you press (hold) button or release it
OnMessage(0x00FF, "InputMsg")
Gui,+AlwaysOnTop
Gui,Show
GuiHandle := WinExist()
AHKHID_Register(12, 1,GuiHandle)
return
InputMsg(wParam, lParam) {
Local r, h
Critical ;Or otherwise you could get ERROR_INVALID_HANDLE
If (AHKHID_GetInputInfo(lParam, II_MSE_RAWBUTTONS) != 0)
ToolTip,% AHKHID_GetInputInfo(lParam, II_MSE_RAWBUTTONS)

}

GuiClose:
ExitApp

Re: Griffin Powermate (USB) AHKHID script

Posted: 11 Aug 2018, 03:58
by Rudantu
Hi, this script is so close to perfect for me, however my model of powermate shows up as a mouse (NOT a HID, so different usage page, identifying values such as no. of buttons instead of vendor ID, and will be outputting mouse-position-changes not keys)

Could you help me adjust your script to work with a mouse instead of HID? I've tried analyzing other mouse related scripts and hacking yours to match but alas, I am new to scripting and can't figure it out.

Re: Griffin Powermate (USB) AHKHID script

Posted: 11 Aug 2018, 18:02
by Stevie
Hm, is it the USB version or Bluetooth?
Do you have the driver installed? I'm not 100% sure but it could be, that it behaves like a mouse, when the driver is loaded.

Re: Griffin Powermate (USB) AHKHID script

Posted: 25 Aug 2018, 01:49
by erebus
Hello,
Thank you very much for the script.
I'm new on AutoHotKey and i have some probleme.

This work fine for me:

Code: Select all

If (key == 16711680) ; turn Powermate left
		SendInput {WheelDown} ;send mousewheel down
	
	If (key == 65536) ; turn Powermate right
		SendInput {WheelUp} ;send mousewheel up
let's go to my problems
1. those don't work (Im Testing, is why i sending text)

Code: Select all

	If (key == 256) ; press button
		SendInput text ;assign your own action
		
	If (key == 16711936) ; press button + turn Powermate left
		SendInput Hello ;assign your own action
		
	If (key == 65792) ; press button + turn Powermate right
		SendInput bonjour ;assign your own action
2. is this normal that "Long Press Button" is Missing ?

3. How i create a focus for: Windows, Vivaldi, Musicbee Or Notepad++ etc...
(I read these two links but I don't understand
https://autohotkey.com/docs/commands/WinActivate.htm
https://autohotkey.com/docs/commands/ControlFocus.htm).

4. How i mix "Control" & turn Powermate left by example.

My:
Windows 10 Pro 64bits
PowerMate USB MASM-03169
AutoHotKey 1.1.29.01

Thanks in advance for your help

Erebus

PS. Sorry for my bad english

Re: Griffin Powermate (USB) AHKHID script

Posted: 03 Jul 2019, 08:22
by Nick A
Hi All,

I'm having issues getting this to work in 2019 in Windows 10. The script runs but seems to have no effect.

I've changed these variables as required in the script as so:

If (devh <> -1)
And (AHKHID_GetDevInfo(devh, DI_DEVTYPE, True) = RIM_TYPEHID)
And (AHKHID_GetDevInfo(devh, DI_HID_VENDORID, True) = 077D) ;Replace these three
And (AHKHID_GetDevInfo(devh, DI_HID_PRODUCTID, True) = 0410) ;numbers with your
;And (AHKHID_GetDevInfo(devh, DI_HID_VERSIONNUMBER, True) = 8) ;devices numbers.
{

based on these properties found on my computer:

2019-07-03 21_05_04-Start.png
2019-07-03 21_05_04-Start.png (16.8 KiB) Viewed 3424 times

I had no idea where to find the DevInfo number so I have left it as 8 and and also tried 1.

Are there any obvious issue that are preventing this script from running as designed?

Also, can you have the official driver installed and/or running (I've tried all ways)?

Thank you.

Re: Griffin Powermate (USB) AHKHID script

Posted: 25 Jun 2023, 06:05
by thric3
To revive this, I have commented out a cautious check and it is now working for me. I'd imagine the odds of it being needed are very low and might only matter if you have many USB devices. Did I hack good?

Code: Select all

SetWorkingDir %A_ScriptDir%
#include ahkhid.ahk
#InstallKeybdHook ;install keyboard hook, enables you to use modifier keys in conjunction with the Powermate

Gui, +LastFound
GuiH := WinExist()

;Intercept WM_INPUT messages
WM_INPUT := 0xFF
OnMessage(WM_INPUT, "InputMsg")

AHKHID_Register(12, 1,GuiH, RIDEV_INPUTSINK) ;register device

InputMsg(wParam, lParam) 
{
	Local devh, key
	Critical    ;or otherwise you could get ERROR_INVALID_HANDLE

	;get handle of device
	devh := AHKHID_GetInputInfo(lParam, II_DEVHANDLE)

	;If (devh <> -1)
        ;And (AHKHID_GetDevInfo(devh, DI_DEVTYPE, True) = RIM_TYPEHID)
        ;And (AHKHID_GetDevInfo(devh, DI_HID_VENDORID, True) = 077D) ;Replace these three
        ;And (AHKHID_GetDevInfo(devh, DI_HID_PRODUCTID, True) = 0410) ;numbers with your
        ;And (AHKHID_GetDevInfo(devh, DI_HID_VERSIONNUMBER, True) = 10) ;devices numbers.
        ;{

		;get the keycode
		key := (AHKHID_GetInputInfo(lParam, II_MSE_RAWBUTTONS))
	
		If (key == 16711680) ; turn Powermate left
		SendInput {Volume_Down} ;send mousewheel down
	
		If (key == 65536) ; turn Powermate right
		SendInput {Volume_Up} ;send mousewheel up
	
		If (key == 256) ; press button
		SendInput {Media_Next} ;assign your own action
		
		;If (key == 16711936) ; press button + turn Powermate left
		;assign your own action
		
		;If (key == 65792) ; press button + turn Powermate right
		;assign your own action
	  ;}

}