Multiple shortcuts on Wacom "Express Keys"

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
schwarzgrau
Posts: 23
Joined: 01 Nov 2015, 11:16
Location: Germany
Contact:

Multiple shortcuts on Wacom "Express Keys"

12 Nov 2015, 12:08

I tried to access the "Express Keys" of my Wacom Cintiq Companion to get more than one hotkey out of a button. Most of the time, KeyWait is used for things like this, but the KeyboardHook brakes this function on my Express Keys. Since I didn't find something about it I wrote some code, which avoids using KeyWait and thought I could share it here, for others with the same problem.
I'm fairly new to AutoHotkey, so if something is written bad (chances are pretty high, since I mostly modified stuff from the manual), please tell me and I try to change it.



SINGLE & DOUBLE
This one is from the manual. It sends out a if pressed once and b if pressed twice.

Code: Select all

F20::
	If (A_PriorHotKey = "F20" AND A_TimeSincePriorHotkey < 900){
	  SendInput, b 			       ;DOUBLE - b
	  SetTimer, F20Default, Off
	}Else
	  SetTimer, F20Default, -900
	Return

	F20Default:
	  SendInput, a 			      ;SINGLE - a
Return


SHORT & LONG I
Sends out a if pressed short and b if pressed long. Both keys get send after releasing the button.

Code: Select all

F20::Return
 
F20 Up::
	If (A_PriorHotKey = "F20" AND A_TimeSincePriorHotkey < 400) 
		SendInput, a		        ;SHORT - a
	Else If (A_PriorHotKey = "F20" AND A_TimeSincePriorHotkey > 400)
		SendInput, b 			;LONG - b
Return


SHORT & LONG II
This one sends out a if pressed short and b if pressed long. The b gets send after 600ms are over, even if the button isn't yet released. The downside is, that the a button also needs 600ms, even if the button releases earlier, which makes it unusable for fast actions.

Code: Select all

F20::
	f20_up = 0
	SetTimer, KeyF20, 600
Return

F20 Up::
	f20_up = 1
Return

KeyF20:
	SetTimer, KeyF20, off
	If (f20_up = 1) 
		SendInput, a 	   		;SHORT - a 
	Else {	
		SendInput, b			;LONG - b	
	}
Return


TOGGLE
I guess this one is from the manual too. A simple a - b toggle

Code: Select all

F20::
	toggle:=!toggle			
	if toggle
		SendInput, a	;TOGGLE - a-b
	Else 
		SendInput, b
Return


SINGLE DOUBLE LONG
This one sends a if you press short, b if your keep the button pressed and c if you double tab it.

Code: Select all

F20::
	f20_up = 0
	if f20_presses > 0
	{
	    f20_presses += 1
	    Return
	}
	f20_presses = 1
	SetTimer, KeyF20, 400
Return

F20 Up::
	f20_up = 1
Return

KeyF20:
	SetTimer, KeyF20, off
	If f20_presses = 1
	{
	    If (f20_up = 1) 
			SendInput, a		;SINGLE - a
		Else 	
	        SendInput, b 			;LONG - b
	}
	Else if f20_presses = 2
	{
	    SendInput, c			        ;DOUBLE - c
	}
	f20_presses = 0
Return


SINGLE DOUBLE TRIPLE
This one is as it is from the manual. It sends out a if pressed one time, b if you double tab it and c if you press it three times in a row.

Code: Select all

F20::
	If f20_presses > 0
	{
	    f20_presses += 1
	    return
	}
	f20_presses = 1
	SetTimer, KeyF20, 400
Return

KeyF20:
	SetTimer, KeyF20, off
	If f20_presses = 1
	{
	    SendInput, a  		;SINGLE - a
	}
	Else If f20_presses = 2 
	{
	    SendInput, b			;DOUBLE - b
	}
	Else If f20_presses > 2
	{
	    SendInput, c			;TRIPLE - c
	}
	f20_presses = 0
Return

HOLD & SINGLE
Keeps Alt pressed if you keep the button pressed and sends out a if you press it shortly.

Code: Select all

F20::
	f20_up = 0
	f20_long = 0
	SetTimer, KeyF20T, 400
Return

F20 Up::
	f20_up = 1
	if(f20_long = 1)
		SendInput, {AltUp}			;RELEASE - Alt	
Return

KeyF20T:
	SetTimer, KeyF20T, off
	If (f20_up = 1) {
		SendInput, a 				;SINGLE - a
	}Else {	
		SendInput, {AltDown}		;HOLD - Alt	
        f20_long = 1
	}
Return


HOLD & DOUBLE
Keeps Alt pressed if you keep the button pressed and sends out a if you double tab it.

Code: Select all

F20::
	If (A_PriorHotKey = "F20 Up" AND A_TimeSincePriorHotkey < 300) {
		SendInput, a					;DOUBLE - a		
	} Else {
		SendInput, {AltDown}			;HOLD - Alt
	}
Return

F20 Up::
	If (A_PriorHotKey = "F20" AND A_TimeSincePriorHotkey > 300) 
		SendInput, {AltUp}
Return
User avatar
evilC
Posts: 4824
Joined: 27 Feb 2014, 12:30

Re: Multiple shortcuts on Wacom "Express Keys"

12 Nov 2015, 14:23

I don't have a wacom to test, but a little advice on dealing with hotkeys:
Keyboard keys (I dunno about wacom buttons) repeat when held.
Test this out to see if it holds true for the wacom

To solve it, simply use a variable to store the state, like you do elsewhere in your code - then for the down binding, check if the state is already down and ignore the down event if it is.

Regarding ...

Code: Select all

SetTimer, KeyF20, 400

[...]

KeyF20:
SetTimer, KeyF20, Off
... If you use SetTimer, KeyF20, -400, it will only trigger once.

If (A_PriorHotKey = "F20" AND A_TimeSincePriorHotkey < 400) If you had another hotkey in the script, this may stop working. If you held F20, then hit another hotkey - this logic breaks down.
To make it more robust, on the down event, store the value of A_TickCount. Then subtract your stored value from A_TickCount at a later point in time to find out the time elapsed since the previous use of this key.
Ignore, I'm wrong. Useful technique tho, so I left it visible.

Otherwise, your code looks good.
User avatar
schwarzgrau
Posts: 23
Joined: 01 Nov 2015, 11:16
Location: Germany
Contact:

Re: Multiple shortcuts on Wacom "Express Keys"

12 Nov 2015, 18:34

Thank you for your advice and for the useful tip with A_TickCount. And I'm happy hearing my code doesn't look that bad, since this is the first time trying to code something for AHK.

The keys on my Wacom device behave a little bit different, then regular keys: Autorepeat seems to be off, so let's say I map a to a button and keep it pressed it sends out a[/a] only a single time, but if I map Alt or Shift on them, it get's constantly pressed. KeyWait did work too, but only if the KeyBoardHook wasn't involved in the script in any way.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 82 guests