Prevent typing letters at the end, when holding a button Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
soheill0098
Posts: 69
Joined: 01 Sep 2020, 12:28

Prevent typing letters at the end, when holding a button

Post by soheill0098 » 12 Apr 2021, 06:28

I remap the hotkey Ctrl+l of Microsoft Edge browser to holding the key l for short time. so when I hold this button for example for half a second, I can write on browser bar of Microsoft Edge to search. but the problem is, when I hold the button for longer time for example 2 seconds it starts typing
lllll
on the search bar. so I am trying to modify following script so that at the end when I hold the button for longer time it doesn't do anything (does not type
lllll
at the search bar).

Here is my script:

Code: Select all

#IfWinActive, ahk_exe msedge.exe
~$l::
KeyWait,l,T0.25
if (ErrorLevel)
{
 send,^l
 sleep,100
 send,{Delete}
 sleep,1000
 send,{Delete}
  }

return

User avatar
mikeyww
Posts: 26940
Joined: 09 Sep 2014, 18:38

Re: Prevent typing letters at the end, when holding a button

Post by mikeyww » 12 Apr 2021, 08:20

You can remove the tilde to avoid the repetitions.
soheill0098
Posts: 69
Joined: 01 Sep 2020, 12:28

Re: Prevent typing letters at the end, when holding a button

Post by soheill0098 » 12 Apr 2021, 11:08

mikeyww wrote:
12 Apr 2021, 08:20
You can remove the tilde to avoid the repetitions.
Thank you! But there is still an issue with

Code: Select all

$l
: it cause problems for typing the words that contain
l
it cause the letters of the words be disarranged when I type them quickly. I had this problem before. in this post : https://www.autohotkey.com/boards/viewtopic.php?f=76&t=88365
Rohwedder
Posts: 7647
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Prevent typing letters at the end, when holding a button

Post by Rohwedder » 12 Apr 2021, 11:37

Hallo,
perhaps:

Code: Select all

#IfWinActive, ahk_exe msedge.exe
$l::
SendInput, l
KeyWait,l,T0.25
if (ErrorLevel)
{
	send,^l
	sleep,100
	send,{Delete}
	sleep,1000
	send,{Delete}
}
KeyWait,l
return
or:

Code: Select all

#IfWinActive, ahk_exe msedge.exe
$l::
KeyWait,l,T0.25
if (ErrorLevel)
{
	send,^l
	sleep,100
	send,{Delete}
	sleep,1000
	send,{Delete}
	KeyWait, l
}
Else
	SendInput, l
return
soheill0098
Posts: 69
Joined: 01 Sep 2020, 12:28

Re: Prevent typing letters at the end, when holding a button

Post by soheill0098 » 12 Apr 2021, 12:00

Rohwedder wrote:
12 Apr 2021, 11:37
Hallo,
perhaps:

Code: Select all

#IfWinActive, ahk_exe msedge.exe
$l::
SendInput, l
KeyWait,l,T0.25
if (ErrorLevel)
{
	send,^l
	sleep,100
	send,{Delete}
	sleep,1000
	send,{Delete}
}
KeyWait,l
return
or:

Code: Select all

#IfWinActive, ahk_exe msedge.exe
$l::
KeyWait,l,T0.25
if (ErrorLevel)
{
	send,^l
	sleep,100
	send,{Delete}
	sleep,1000
	send,{Delete}
	KeyWait, l
}
Else
	SendInput, l
return
Hello, Thank you very much! I used the first one and it works!
soheill0098
Posts: 69
Joined: 01 Sep 2020, 12:28

Re: Prevent typing letters at the end, when holding a button

Post by soheill0098 » 12 Apr 2021, 12:51

Rohwedder wrote:
12 Apr 2021, 11:37
Hallo,
perhaps:

Code: Select all

#IfWinActive, ahk_exe msedge.exe
$l::
SendInput, l
KeyWait,l,T0.25
if (ErrorLevel)
{
	send,^l
	sleep,100
	send,{Delete}
	sleep,1000
	send,{Delete}
}
KeyWait,l
return
or:

Code: Select all

#IfWinActive, ahk_exe msedge.exe
$l::
KeyWait,l,T0.25
if (ErrorLevel)
{
	send,^l
	sleep,100
	send,{Delete}
	sleep,1000
	send,{Delete}
	KeyWait, l
}
Else
	SendInput, l
return

I just realized that there is an issue when I use this script. I use Persian language on the keyboard as an alternative language for English. so when my keyboard is on Persian language and I press the button l on keyboard, rather than typing the Persian letter for the button which is " م " it types " l ". Can you please help me to fix this?
Rohwedder
Posts: 7647
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Prevent typing letters at the end, when holding a button  Topic is solved

Post by Rohwedder » 13 Apr 2021, 02:23

Untested!:

Code: Select all

#IfWinActive, ahk_exe msedge.exe
$SC026::
SendInput, {SC026}
KeyWait, SC026, T0.25
if (ErrorLevel)
{
	send,^l
	sleep,100
	send,{Delete}
	sleep,1000
	send,{Delete}
}
KeyWait, SC026
return
or:

Code: Select all

#IfWinActive, ahk_exe msedge.exe
$SC026::
KeyWait, SC026, T0.25
if (ErrorLevel)
{
	send,^l
	sleep,100
	send,{Delete}
	sleep,1000
	send,{Delete}
	KeyWait, SC026
}
Else
	SendInput, {SC026}
return
soheill0098
Posts: 69
Joined: 01 Sep 2020, 12:28

Re: Prevent typing letters at the end, when holding a button

Post by soheill0098 » 13 Apr 2021, 09:19

Rohwedder wrote:
13 Apr 2021, 02:23
Untested!:

Code: Select all

#IfWinActive, ahk_exe msedge.exe
$SC026::
SendInput, {SC026}
KeyWait, SC026, T0.25
if (ErrorLevel)
{
	send,^l
	sleep,100
	send,{Delete}
	sleep,1000
	send,{Delete}
}
KeyWait, SC026
return
or:

Code: Select all

#IfWinActive, ahk_exe msedge.exe
$SC026::
KeyWait, SC026, T0.25
if (ErrorLevel)
{
	send,^l
	sleep,100
	send,{Delete}
	sleep,1000
	send,{Delete}
	KeyWait, SC026
}
Else
	SendInput, {SC026}
return
Wow! I used the first one and it worked! thanks a lot!
Post Reply

Return to “Ask for Help (v1)”