Long press is not working Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Rohwedder
Posts: 7695
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Long press is not working

23 Apr 2024, 08:01

No problem here with US, GB and DE keyboard.
Actually, the script should only react to modifier variations of the 1 key.
Which keyboard layout are you using?:

Code: Select all

; Hotkey F4 shows the keyboard scheme valid for the active window.
; The url calculation may not fit everywhere!
Lang := {0x4090409:"United States (en-US)", 0x8090809:"United Kingdom (en-GB)"
, 0x4070407:"Germany (de-DE)", 0x40C040C: "France (fr-FR)"}
; +-------------------------+-------------------------+
; |     SubLanguage ID      |   Primary Language ID   |
; +-------------------------+-------------------------+
; 15                    10  9                         0   bit
Return
F4::
ControlGetFocus Focused, A
ControlGet CtrlID, Hwnd,, % Focused, A
ThreadID := DllCall("GetWindowThreadProcessId", "Ptr", CtrlID, "Ptr", 0)
InputLocaleID := Format("0x{:04X}",DllCall("GetKeyboardLayout", "UInt", ThreadID, "Ptr"))
MsgBox,4,,% InputLocaleID " = " Lang[InputLocaleID] "`nWant to see your keyboard at http://kbdlayout.info ?"
LanguageID := Format("{:08X}", InputLocaleID & 0xFFFF)
IfMsgBox Yes
	Run, http://kbdlayout.info/%LanguageID%
Return
Joey5
Posts: 97
Joined: 19 May 2023, 05:25

Re: Long press is not working

23 Apr 2024, 20:54

@Rohwedder Thank you for your followup. I have used your scripts to create 25 some macros at work. Greatly appreciate it. Today keys like 1,2,3 and 4 randomly stopped working like "\" yesterday. And worked fine when the scripts was exited. perpelxed.

I will run your script at work and see what keyboard type I am using. TY.
Joey5
Posts: 97
Joined: 19 May 2023, 05:25

Re: Long press is not working

24 Apr 2024, 13:04

Using 0x4090409:"United States (en-US) keyboard layout. As a different subject, In the winexist script in this thread, it applies long press to specific program and short press for any open program. Like in excel, is it possible to apply one more condition so that the scripts says ifwinexist program ABC, send xyz with long press, if winexist program ABC send lmn with short press and if program ABC not winexist apply to any open program. TY.
Joey5
Posts: 97
Joined: 19 May 2023, 05:25

Re: Long press is not working

24 Apr 2024, 13:15

I meant winexist long press command one to specified program.
winexist short press command two to specified program (same as above)
nonwinexist send command three to any active program.
TY.
Joey5
Posts: 97
Joined: 19 May 2023, 05:25

Re: Long press is not working

24 Apr 2024, 19:53

I could use the following.

Code: Select all

#IFWinActive, ahk_exe notepad.exe
$d::
keywait, d, T0.5
if errorlevel {
	SoundBeep
	Send e
} else Send d
keywait, d
; d key down would immediately trigger $d:: again
return
#IFWinActive
Last edited by gregster on 24 Apr 2024, 21:04, edited 1 time in total.
Reason: Fixed code tags. These tags should go around the code.
Rohwedder
Posts: 7695
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Long press is not working

25 Apr 2024, 02:47

Today keys like 1,2,3 and 4 randomly stopped working like "\" yesterday.
No one is perfect, least of all computers! Add to your script(s):

Code: Select all

~$*Esc::
KeyWait, Esc, T1
IF !ErrorLevel
	Return ; if held for less than 1 second
SoundPlay, %A_WinDir%\Media\chord.wav, 1
For all, LF in [[0x1FF,"sc{:X}"],[0xFE,"vk{:X}"]]
    Loop,% LF.1 ;release all pressed keys
        IF (""<Key:=GetKeyName(Format(LF.2, A_Index)))
            SendInput, {%Key% up}{Esc}
Reload
If any keys fail, press and hold the Escape key for one second, a sound is heard, all keys are reset and the script is restarted.
I meant winexist long press command one to specified program.
winexist short press command two to specified program (same as above)
nonwinexist send command three to any active program.
I don't get it! That's too much ambiguity at once.
1. A script cannot send to programmes! Only to windows!
So it doesn't matter whether one or more programmes are active or inactive, only windows are of interest!
2. Do not confuse the window states of being existent or active. Exactly one window is both: existing and active, and therefore the addressee of Send and SendTimer().
All other existing windows are not active and can therefore only be the addressee of sendings with ControlSend or ControlClick, if at all!
(If you have a non-existent active window, you need at least a break.)
Joey5
Posts: 97
Joined: 19 May 2023, 05:25

Re: Long press is not working

25 Apr 2024, 05:07

Thank you. The scripts add so much efficiency and convenience that I don’t mind rebooting the script. I did that 2-3 times yesterday. That is not a problem at all. I will add the escape script. Thank you very much. I was carrying vial loaded keyboard everywhere. Yesterday, I was able to ditch it and get the same functionality with AHK scripts. 8-)
Joey5
Posts: 97
Joined: 19 May 2023, 05:25

Re: Long press is not working

30 Apr 2024, 05:20

@Rohwedder thank you for the reset script. I end up needing it once or twice a day. Very useful. All offshoot scripts are working well. Wanted to give you follow up and thank you and others like you here who help us constantly!
Joey5
Posts: 97
Joined: 19 May 2023, 05:25

Re: Long press is not working

02 May 2024, 15:57

@Rohwedder In keeping up with the long press theme is it possible to have a script where long press of the same key toggles through 3-4 commands. I know how to do short press toggle for two commands but no clue if and how one toggles through 3-4 commands by long pressing the same key. Thank you in advance.
Rohwedder
Posts: 7695
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Long press is not working

03 May 2024, 02:14

E.g.:

Code: Select all

q::
KeyWait,% Counter() ; counts every 500 ms
Switch No {
Case 1:MsgBox do first Task
Case 2:MsgBox do second Task
Case 3:MsgBox do third Task
; ...
} Return

!w::
KeyWait,% Counter(1000) ; counts every 1000 ms
Switch No {
Case 1:MsgBox do first Task
Case 2:MsgBox do second Task
Case 3:MsgBox do third Task
; ...
} Return

Counter(Time := 500) {
	Global Counter := Func(A_ThisFunc).Bind(Time), No
	RegExMatch(A_ThisHotkey, "\W$|\w*$", Key)
	IF GetKeyState(Key, "P") {
		SetTimer,% Counter,% -Time := Abs(Time)
		ToolTip,% "Case " No:=1+A_TimeSinceThisHotkey//Time
	} Else ToolTip
	Return, Key
}
Joey5
Posts: 97
Joined: 19 May 2023, 05:25

Re: Long press is not working

03 May 2024, 06:44

@Rohwedder thank you so much. the script works great. I will be able to use it regularly. Is it possible to have something where it is not time sensitive but cycles through case 1 to case 5? Regular tap instead of short tap is fine (or almost better). In other words, on tap 1, it sends command 1. Then next time it is tapped, it sends commend 2, one more tap in the future it sends command 3... basically cycles through 5 commands and starts over. Not time sensitive but tap counter specific. Thank you in advance.
Joey5
Posts: 97
Joined: 19 May 2023, 05:25

Re: Long press is not working

03 May 2024, 06:52

The following seems to do the trick for numpad. But what if you want different kind of commands? TY.

Code: Select all

; Initialize the counter
counter := 1

; Hotkey for the "\" key
\::
    ; Increment the counter
    counter := (counter = 5) ? 1 : counter + 1

    ; Send the corresponding Numpad key
    Send, {Numpad%counter%}
return
Joey5
Posts: 97
Joined: 19 May 2023, 05:25

Re: Long press is not working

03 May 2024, 08:04

The following seems to do the trick.

Code: Select all

; Define the commands for each tap
commands := ["command 1", "command 2", "command 3", "command 4", "command 5"]

; Initialize the counter
counter := 1

; Hotkey for the "\" key
\::
    ; Execute the corresponding command
    Send, % commands[counter]

    ; Increment the counter
    counter := (counter = 5) ? 1 : counter + 1
return
Joey5
Posts: 97
Joined: 19 May 2023, 05:25

Re: Long press is not working

05 May 2024, 08:10

Why does the above script only work in isolation? When added to a larger .ahk file containing several other scripts, it fails to work. Othe scripts continue to work. TY.
Rohwedder
Posts: 7695
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Long press is not working

05 May 2024, 12:08

Maybe the definition of the commands and the initialization of the counter are not in the auto-execute section (at the beginning of the script)?
Try:

Code: Select all

\::Send,% ["command 1", "command 2", "command 3"
, "command 4", "command 5"][++BSL:=Mod(0 BSL, 5)]
Explanation of: ++BSL:=Mod(0 BSL, 5)
BSL is the counter of that backslash Hotkey
0 is used for initialization
5 is the number of commands
Joey5
Posts: 97
Joined: 19 May 2023, 05:25

Re: Long press is not working

05 May 2024, 12:39

@Rohwedder thank you as always. I will try it. Meanwhile, putting the script before other scripts worked. I had put the following reset script by you before all other scripts. Not it is in second position. Hope that does not make it ineffective. TY.

Code: Select all

; Long press the escape key to reload and reset all scripts
~$*Esc::
KeyWait, Esc, T1
IF !ErrorLevel

SoundPlay, %A_WinDir%\Media\chord.wav, 1
For all, LF in [[0x1FF,"sc{:X}"],[0xFE,"vk{:X}"]]
    Loop,% LF.1 ;release all pressed keys
        IF (""<Key:=GetKeyName(Format(LF.2, A_Index)))
            SendInput, {%Key% up}{Esc}
Reload
Rohwedder
Posts: 7695
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Long press is not working

05 May 2024, 12:44

Just to clarify! My backslash Hotkey script above does not require anything in the auto-execute section.
Joey5
Posts: 97
Joined: 19 May 2023, 05:25

Re: Long press is not working

05 May 2024, 20:01

I’ll try or script at work tomorrow. Thank you.
Joey5
Posts: 97
Joined: 19 May 2023, 05:25

Re: Long press is not working

06 May 2024, 16:07

@Rohwedder following up with the latest BSL script from you. Trie it. Works like a charm. THank you much.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Chunjee, inseption86, mihai369, Rohwedder and 104 guests