RCtrl long press

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
mikagenic
Posts: 93
Joined: 16 Sep 2014, 18:26

RCtrl long press

27 May 2017, 03:02

I am trying to capture long press on right control

I tried:

Code: Select all

RCtrl::
OutputDebug "here1"
KeyWait, RCtrl, T0.5 ; Wait no more than 0.5 sec
If ErrorLevel { ; timeout, long press
	OutputDebug "here2"
} else { ; short press
	OutputDebug "here3"
}
return
But I don't get "here2" on long press

short press works fine, and also short and long press work fine if I replace RCtrl with LCtrl or RAlt for example

what am I doing wrong ?

(tested with DebugView)
Rohwedder
Posts: 7630
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: RCtrl long press

27 May 2017, 09:58

Hallo,
try:

Code: Select all

RCtrl::
	RCtrlPressTime := -A_TickCount
	KeyWait, RCtrl
	RCtrlPressTime -= -A_TickCount
	MsgBox, % "RCtrlPressTime: "RCtrlPressTime " ms"
Return
Simply measure the time and then decide whether it was short or long.
mikagenic
Posts: 93
Joined: 16 Sep 2014, 18:26

Re: RCtrl long press

27 May 2017, 20:12

Thanks for the reply !

This will not work for me, it will only execute the short/long press code after the RCtrl is released whereas I need the long press handler to execute after the timeout is expired (while the key is still held down).

The code I posted in the original question works for other keys, why does keywait with timeout doesn't work RCtrl ?

can anyone else reproduce it ?

Thanks!
Rohwedder
Posts: 7630
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: RCtrl long press

28 May 2017, 00:51

Hallo,
I have no debugger, so I tried:

Code: Select all

RCtrl::
	KeyWait, RCtrl, T0.5 ; Wait no more than 0.5 sec
	If ErrorLevel ; timeout, long press
		MsgBox, long press
	else ; short press
		MsgBox, short press
return
No problem, it works!
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: RCtrl long press

28 May 2017, 00:54

There must be something wrong on all of the machines you tested on (such as common hardware or drivers, or software other than this one script).

For example, if the RCtrl key appears to be artificial, either because it is intercepted by other software or because of some quirk of the drivers, KeyWait will detect its physical state as "up" immediately, and will have no reason to wait. In that case, KeyHistory will show that it is artificial. You can either avoid blocking the key (use ~RCtrl::) and wait on the logical (L) state, or use a combination of key-up hotkey (RCtrl up::) and timers/sleep to implement the timeout.
mikagenic
Posts: 93
Joined: 16 Sep 2014, 18:26

Re: RCtrl long press

29 May 2017, 17:03

Great thx lexicos !

I solved it like this:

Code: Select all

~RCtrl::
KeyWait, RCtrl, L T0.3
err := ErrorLevel
Send {RCtrl up}
If %err% { 
	OutputDebug "long"
} else { ; short press
	OutputDebug "shor"
}
Keywait, RCtrl
return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: scriptor2016 and 322 guests