Second script blocks first, if used on Wacom Expresskeys

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
schwarzgrau
Posts: 23
Joined: 01 Nov 2015, 11:16
Location: Germany
Contact:

Second script blocks first, if used on Wacom Expresskeys

09 Nov 2015, 07:19

I'm using a Wacom Cintiq Companion 2, running Windows 10. The Companion has some "ExpressKeys" on the left, which I want to control with AutoHotkey, to get more shortcuts out of them.
Image

So I used the Wacom-driver to map the F-keys to the buttons and wrote a script to add extra functions.
This one sends out g if pressed long and the left arrow if pressed short.

Code: Select all

F8::                                              
    KeyWait, F8, T0.5                              
    If ErrorLevel {                                    
        SendInput g 			;LONG - g 		                          
        KeyWait, F8
    }Else {                                               
        SendInput {Left}   		;SHORT - left                                   
	}
Return
Everything works like expected, till I add one of the modifier keys like LWin::, Alt::, Ctrl:: etc. or if I add #IfWinActive. Then all parts of the script which uses KeyWait brake.
If I use the same script with my regular keyboard everything works fine, so I guess it has something to do with the keys of the wacom-device, but I don't know how to address it.
Maybe I should mention the regular behavior of these ExpressKeys: If I map shift on one of them and keep it pressed shift will be send as long as I press it, but if I map a to them it just sends out a single a, even if I press the button for a long time.
User avatar
sinkfaze
Posts: 616
Joined: 01 Oct 2013, 08:01

Re: Second script blocks first, if used on Wacom Expresskeys

09 Nov 2015, 09:47

I don't think AutoHotkey has any guarantees for working on tablets.
User avatar
schwarzgrau
Posts: 23
Joined: 01 Nov 2015, 11:16
Location: Germany
Contact:

Re: Second script blocks first, if used on Wacom Expresskeys

09 Nov 2015, 09:51

Of course not, I thought maybe the keys are some kind of "virtual keys" or something like this and there could be a known fix for my problem.
lexikos-nli

Re: Second script blocks first, if used on Wacom Expresskeys

09 Nov 2015, 21:57

Does KeyHistory show the Wacom buttons as artificial?

You can try using F8::, F8 up::, A_PriorHotkey and A_TimeSincePriorHotkey instead of KeyWait.
User avatar
schwarzgrau
Posts: 23
Joined: 01 Nov 2015, 11:16
Location: Germany
Contact:

Re: Second script blocks first, if used on Wacom Expresskeys

10 Nov 2015, 05:56

The KeyHistory only show them if I map a "regular" key on them. If I use one of the "special features" like "touch controls on" nothing is displayed in the KeyHistory

Neither F8 up::, nor F8 Up:: seems to be avaible in AHK, but A_Priorhotkey and A_TimeSincePriorHotkey are a great suggestion. Unfortunately I already use them and it seems their function get's blocked too, by LWin:: and #IfWinActive.

A bit like AHK would only accept single shots from this buttons if I use a modifier or #IfWinActive.

Code: Select all

F7::
	If (A_PriorHotKey = "F7" AND A_TimeSincePriorHotkey < 500)
	{
		SendInput +{Home}				;DOUBLE - shiftHome - RotReset
	}Else {
		SendInput {CtrlDown}{AltDown}
		KeyWait, F7, Off 				;LONG - CtrlAlt - Rotation
		SendInput {CtrlUp}{AltUp}
	}
Return
This is the part which uses A_PriorHotKey. It keeps CTRL+ALT pressed if the button gets pressed long and sends SHIFT+HOME if double pressed.

By the way if I run an action for LWin:: in a second script together with my original script it works fine, but #IfWinActive gets a bit useless if it's running in a second script.
lexikos
Posts: 9678
Joined: 30 Sep 2013, 04:07
Contact:

Re: Second script blocks first, if used on Wacom Expresskeys

10 Nov 2015, 16:44

The KeyHistory only show them if I map a "regular" key on them.
And is this "regular" key shown as artificial? I suppose it would be, since it is.

KeyWait waits for the physical state of the key by default if the keyboard hook is installed. LWin:: and #IfWinActive require the keyboard hook.
Neither F8 up::, nor F8 Up:: seems to be avaible in AHK,
What are you talking about? Both have been valid hotkeys for as long as I can remember.
Unfortunately I already use them and it seems their function get's blocked too, by LWin:: and #IfWinActive.
Blocked how? If the hotkey is pressed, it will end up in A_PriorHotkey/A_TimeSincePriorHotkey after a second hotkey is pressed (or the same hotkey again). The only way it could be "blocked" is if the hotkey never executed in the first place, or if you press some other hotkey in between, which becomes the new A_PriorHotkey.


See if *F8::/*F7:: makes any difference. The wildcard ensures the hotkey can fire even if the system thinks you're holding a modifier key.
User avatar
schwarzgrau
Posts: 23
Joined: 01 Nov 2015, 11:16
Location: Germany
Contact:

Re: Second script blocks first, if used on Wacom Expresskeys

10 Nov 2015, 17:36

Sorry, some things still confusing me, I'm using AHK only since 5 days, I'm not familiar with everything.
lexikos wrote:And is this "regular" key shown as artificial? I suppose it would be, since it is.
Yea, if I press one of the Express-Keys they get listed in the KeyHistory, if I map a regular keyboard function on them (like F8 or ctrl+A). But they get listed as artifical.
lexikos wrote:KeyWait waits for the physical state of the key by default if the keyboard hook is installed. LWin:: and #IfWinActive require the keyboard hook.
Thank you, that explains a lot.
lexikos wrote:What are you talking about? Both have been valid hotkeys for as long as I can remember.
Weird, If I use F8 Up::a I get this error-message:

Code: Select all

Error: Invalid hotkey.

Specifically: *F8 Up up::

	Line#
	003: SendMode,Input
	004: SetWorkingDir,%A_ScriptDir%
	015: Return
	015: SetKeyDelay,-1
	015: Send,{Blind}{a DownTemp}
--> 015: Return	

The program will exit.
lexikos wrote:Blocked how? If the hotkey is pressed, it will end up in A_PriorHotkey/A_TimeSincePriorHotkey after a second hotkey is pressed (or the same hotkey again). The only way it could be "blocked" is if the hotkey never executed in the first place, or if you press some other hotkey in between, which becomes the new A_PriorHotkey.
Sorry I was confused by the "not-working"-part of the script. Only the long press doesn't work (cause it uses KeyWait too), but the double-tapping part, which uses A_PriorHotkey still works.
lexikos wrote:See if *F8::/*F7:: makes any difference. The wildcard ensures the hotkey can fire even if the system thinks you're holding a modifier key.
Unfortunately the wildcard brakes the KeyWait too
lexikos
Posts: 9678
Joined: 30 Sep 2013, 04:07
Contact:

Re: Second script blocks first, if used on Wacom Expresskeys

10 Nov 2015, 21:36

schwarzgrau wrote:Weird, If I use F8 Up::a I get this error-message:
What are you doing that for? Are you trying to remap F8-up to the letter 'a'? "Keyname up" is not valid for a remapping (onekey::otherkey), only for a hotkey.
Unfortunately the wildcard brakes the KeyWait too
I assumed you already have LWin::, #IfWin or something else which "brakes the KeyWait" (N.B. the appropriate word is "break" as in "broken"), and the point was to see if adding the wildcard made an improvement. Apparently it would not.

You are most likely going to want to use something which requires the hook, so forget about avoiding it.
Only the long press doesn't work (cause it uses KeyWait too)
Post the code you used. My suggestion was to use A_TimeSincePriorHotkey in combination with a key-up hotkey, instead of KeyWait. Sorry if this wasn't clear.

In the F8 up hotkey, if A_PriorHotkey is F8, A_TimeSincePriorHotkey returns how long you held F8.
User avatar
schwarzgrau
Posts: 23
Joined: 01 Nov 2015, 11:16
Location: Germany
Contact:

Re: Second script blocks first, if used on Wacom Expresskeys

11 Nov 2015, 05:42

Sorry I didn't understood before. I hope I got it now and thank you for your patience

This part continously sends out CTRL+ALT if pressed long and a single time SHIFT+HOME if double tapped

Code: Select all

F7::
	If (A_PriorHotKey = "F7" AND A_TimeSincePriorHotkey < 500)
	{
		SendInput +{Home}				;DOUBLE - shiftHome - RotReset
	}Else {
		SendInput {CtrlDown}{AltDown}
		KeyWait, F7, Off 				;LONG - CtrlAlt - Rotation
		SendInput {CtrlUp}{AltUp}
	}
Return
Now I changed this part to use F7:: Up and everything seems to work

Code: Select all

F10::
	If (A_PriorHotKey = "F10 Up" AND A_TimeSincePriorHotkey < 300) {
		SendInput ^l			;DOUBLE - ctrL - lighttable	
	} Else {
		SendInput, {AltDown}	;LONG - Alt - Pan
	}
Return

F10 Up::
	If (A_PriorHotKey = "F10" AND A_TimeSincePriorHotkey > 300) 
		SendInput, {AltUp}
Returnn

A bit harder to modify is this part which uses a long press to send out one shortcut if pressed short and another if pressed long.

Code: Select all

F8::                                              
    KeyWait, F8, T0.5                              
    If ErrorLevel {                                    
        SendInput g 			;LONG - g - delete head 			                          
        KeyWait, F8
    }Else {                                               
        SendInput {Left}   		;SHORT - left - prev frame                                  
	}
Return
I tried it this way, but it seems to do nothing and I don't know why

Code: Select all

F8 Up::
	If (A_PriorHotKey = "F8" AND A_TimeSincePriorHotkey < 200) 
		SendInput {Left}		;SHORT - left - prev frame 
	Else If (A_PriorHotKey = "F8" AND A_TimeSincePriorHotkey > 200)
		SendInput g 			;LONG - g - delete head
Return
Last edited by schwarzgrau on 11 Nov 2015, 06:12, edited 1 time in total.
User avatar
schwarzgrau
Posts: 23
Joined: 01 Nov 2015, 11:16
Location: Germany
Contact:

Re: Second script blocks first, if used on Wacom Expresskeys

11 Nov 2015, 06:31

Your question suggests that I have to define a F8:: hotkey, but since I don't need a hotkey there, is there something I can set on F8:: what does nothing at all?
User avatar
schwarzgrau
Posts: 23
Joined: 01 Nov 2015, 11:16
Location: Germany
Contact:

Re: Second script blocks first, if used on Wacom Expresskeys

11 Nov 2015, 11:31

Thanks to your help I wrote all parts of the script I need. I thought maybe I should share it in the Script and Functions section for other users which uses the wacom express-keys or similar buttons.
All of them work for my purpose, but maybe I could simplify some things or make them more stable.

DOUBLE PRESS = sends out a single shot
PRESSED LONG = keeps a button pressed (for Alt, Shift etc.)

Code: Select all

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

F1 Up::
	If (A_PriorHotKey = "F1" AND A_TimeSincePriorHotkey > 300) 
		SendInput, {AltUp}
Return

PRESSED SHORT = sends out a single shot
PRESSED LONG = sends out a different single shot

Code: Select all

F1::
	KeyWait, F1
Return

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

Toggles output

Code: Select all

F1::
    atoggle:=!atoggle
	If atoggle 
		SendInput, a 			;TOGGLE 1
	Else 
		SendInput, b 			;TOGGLE 2
Return

SINGLE PRESS = sends out a single shot
DOUBLE PRESS = sends out a different single shot

Code: Select all

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

	F1Default:
	  SendInput, a 			;SINGLE
Return

This one is pretty special and I guess not very well written it sends out a shortcut if pressed (no matter how long) and another if released. A third shortcut is send if double tapped.

Code: Select all

f1::
	f1_long = 0
	f1_up = 0
	if f1_presses > 0 ; 
	{
	    f1_presses += 1
	    Return
	}
	f1_presses = 1
	SetTimer, Keyf1, 300 
Return

f1 Up::
	f1_up = 1
	If (f1_long = 1)
		SendInput, b  		;RELEASE
Return

Keyf1:
	SetTimer, Keyf1, off
	if f1_presses = 1 
	{	
	    SendInput, a  		;PRESS
	    f1_long = 1
	    if f1_up = 1 
	    	SendInput, b  		;RELEASE
	}
	else if (f1_presses = 2)
	    SendInput, c 			;DOUBLE
	f1_presses = 0
Return
lexikos
Posts: 9678
Joined: 30 Sep 2013, 04:07
Contact:

Re: Second script blocks first, if used on Wacom Expresskeys

11 Nov 2015, 16:27

schwarzgrau wrote:Your question suggests that I have to define a F8:: hotkey,
Yes, that's right. If you don't define F8 as a hotkey, how can it become A_PriorHotkey?
but since I don't need a hotkey there, is there something I can set on F8:: what does nothing at all?
How do you define a hotkey which does something?

Code: Select all

F8::
    do something
return
So just define a hotkey which doesn't "do something".

Code: Select all

F8::

return
For short,

Code: Select all

F8::return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 172 guests