Artificial Single Double Long Help

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Elakwia

Artificial Single Double Long Help

26 Apr 2018, 03:34

Hello, I'm new to the ATH and trying to learn, but for me its by trial and error. I tried writing and searching for my problem but can't figure it out.
I tried few different methods with AKH Documentation or merging codes that i found. It's to extend functionality of a key for Single, Double or Long Tap.

Code: Select all

#SingleInstance force
LShift::
	analyseKeyPress("b","/","{LShift Down}","{LShift Up}")
return
LControl::
	analyseKeyPress("/","e","{LControl Down}","{LControl Up}")
return

F12::
	analyseKeyPress("5","1","{LShift Down}^{Space Down}","{LShift Up}^{Space Up}")
return

F12 up::
	test = 1
return

analyseKeyPress(singlekey,doublekey,longkey1,longkey0){ ;
	doubleKeySpeed:=0.2 
	longKeyPressTime:=0.3
     keywait, %A_thisHotkey%, t%longKeyPressTime%
      if errorLevel{
         sendinput, %longkey1%
		 KeyWait, %A_thisHotkey%
		 sendinput, %longkey0%
      }else{
         keywait, %A_thisHotkey%, d t%doubleKeySpeed%
         if errorLevel{
            sendinput, %singlekey%                
         }else{
            sendinput, %doublekey%              
         }
      }

      return
   }
return
This sends fe. Shift
  • b (Single Click)
  • / (Double Tap)
  • Holding Shift (Hold)
This works perfect for normal key but not with Artificial keys, even with L on keywait. Keywait just don't work for them. I'm using XP-Pen Deco 01 that simulates LShift with button. In AKHHID buttons have some value when pushed, I don't remember correctly, but fe. K1 is 6001000 and down for every button is 6000000, K2 is 6002000 K3 is 6004000, holdind K1 with K2 its 6003000, but I don't know what to do with this actually.
I found a topic for Wacom tablet and it looks like the same idea. https://autohotkey.com/boards/viewtopic.php?t=10358
I modified this for single, double and long:

Code: Select all

F12::

Return

F12 Up::
	If (A_PriorHotKey = "F12" AND A_TimeSincePriorHotkey > 400) {
		SendInput, u
		} else if (A_PriorHotKey = "f12" AND A_TimeSincePriorHotkey < 100) {
			if (presses > 0) {
				SendInput, d                ;DOUBLE
				presses = 0
			} else {
				presses +=1
			} 
		} else {
			SendInput, s
		}
Return
Becouse it uses a variable, I can't create function from this and I don't want to create a lot lines of code for every button, or long list of variables. Besides, this send ony when i let go of a key, and i want functionality when i push the key for long. I could add sendinput in F12::, but i need that send only when holding. Artificial key don't fire multiple times like normal key, Only once with time elapsed.
7B 058 h d 7.25 F12
7B 058 h u 4.31 F12
55 016 i d 0.00 u
55 016 i u 0.00 u
I tried modifying like this:

Code: Select all

$x::
if GetKeyState("x", "P") {
	SendInput, x
} else {
	If (A_PriorHotKey = "$x Up" AND A_TimeSincePriorHotkey < 400) {
		SendInput, d						
	} Else {
		SendInput, h			
	}
}
	
return

$x Up::
If (A_PriorHotKey = "$x" AND A_TimeSincePriorHotkey > 400) {
	SendInput, l 		
}
Return
With this i can check if its artificial, but still can't figure it out how to add difrent button when holding, and double tapping generates 2 outcomes with single and double (hd) instead of (d). Additionally normal x also sends l, when holding and then clicking other keys.

Long story short I want to create a button for my drawing tablet that with one tap changes to Brush (b) double tap should change to last preset (/) and only when holding it should hold Shift to be able to change brush size.

With this i should be able to create rest of the buttons [single][double][long_down][long_up]. Examples: [a](holding) or [a](when holding send c once, and when stopped send another c to reset).
I wanted to create everything in arrays and loop, but don't know how to create hotkeys inside code and without a lot of labels.
Elakwia

Re: Artificial Single Double Long Help

27 Apr 2018, 01:19

Can't edit posts without account, but a little bump should not be that bad.
I wrote something like this:

Code: Select all

aKPd(key,doublekey,longdown) {
	If (A_PriorHotKey = key " Up" AND A_TimeSincePriorHotkey < 200) {
		SendInput, %doublekey%
		Sleep, 90
	} Else {
	timevar = 0
	Loop {
	If (A_PriorHotKey = key)
	Break
	
	Sleep, 60
	timevar += 1
	If (timevar > 5) {
		SendInput, %longdown%
		Break
	}
	}

}
}

aKPu(key,singlekey,longup) {
	If (A_TimeSincePriorHotkey > 300) {
		SendInput, %longup% 		
	} Else If (A_PriorHotKey = key AND A_TimeSincePriorHotkey > 100 ){
		SendInput, %singlekey%
		Sleep, 90
	}
}
It seems to do the trick. Times might be a little off, but i was eyeballing it. I'm sure there might be a better solution. Hope someone will find it.
Define hotkey:

Code: Select all

F13::
aKPd("F13","/","{LShift Down}")	
return

F13 Up::
aKPu("F13","b","{LShift Up}")
Return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mebelantikjaya and 323 guests