Long press C to send Ç Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
sulphuricsaliva
Posts: 48
Joined: 11 Sep 2018, 12:37

Long press C to send Ç

11 Sep 2018, 13:07

I need a script that allows me to use the C key normaly and long pressing it sending the Ç key.
I've managed to make a script that does that but when I press C in the middle of a word it has some kind of delay, for instante, if I try to write "Corsair" it comes out as ocrsair, unless I type it really, really slowly.
This is what I have so far:

$c::
KeyWait, c, T0.5
If ErrorLevel {
Send {ç}
KeyWait, c
} Else
Send {c}
return

I'm a noob at autokeys, I usually make my scripts by copying similar codes from the internet and change a couple of things by trial and error but this time I'm really stuck. I'm pretty sure this is fairly easy stuff for you guys. Please help me figure this out, it would mean a lot to me.
User avatar
Nextron
Posts: 1391
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: Long press C to send Ç

11 Sep 2018, 16:22

Normally a character is sent when to press down on a key. Using your code, it is sent when you release the key. This makes sense because AHK doesn't know in advance how long you'll be keeping the key pressed. However during quick typing you'll be pressing the next key before releasing this key, resulting in the problem.
Try is small alteration which will send the c on the down event but when you keep it down it will backspace and send the replacement character.

Code: Select all

$*c::
Send {Blind}{c}
KeyWait, c, T0.5
If ErrorLevel {
	Send {BackSpace}{ç}
	KeyWait, c
}
return
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: Long press C to send Ç

11 Sep 2018, 16:46

Here is an alternative to look at:
  • Use triple press c to get ç
  • Use Shift and triple press c gets you Ç. You only need to shift for the first c.

Code: Select all

::ccc::ç
It's not what you asked for, but the uppercase version might make it worthwhile.
sulphuricsaliva
Posts: 48
Joined: 11 Sep 2018, 12:37

Re: Long press C to send Ç

12 Sep 2018, 16:34

Nextron wrote:Normally a character is sent when to press down on a key. Using your code, it is sent when you release the key. This makes sense because AHK doesn't know in advance how long you'll be keeping the key pressed. However during quick typing you'll be pressing the next key before releasing this key, resulting in the problem.
Try is small alteration which will send the c on the down event but when you keep it down it will backspace and send the replacement character.

Code: Select all

$*c::
Send {Blind}{c}
KeyWait, c, T0.5
If ErrorLevel {
	Send {BackSpace}{ç}
	KeyWait, c
}
return
Oh my God it works like a charm!
I'm buying a keyboard with US layout wich I'll have to get used to and this is a great way to make the Ç, wich is used very often in Portuguese. Thank you so much for your help! :)
sulphuricsaliva
Posts: 48
Joined: 11 Sep 2018, 12:37

Re: Long press C to send Ç

13 Sep 2018, 12:21

I'm sorry if I'm pushing it Nextron but would it be possible to add something to the script you gave me so It can send yet another key, depending on how long I press it? Dor instance at the moment if I press c it sends c if I press c for 0.5 sends ç, I wanted to press c for like 0.7 to send A for example. Is it possible?
User avatar
divanebaba
Posts: 804
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: Long press C to send Ç

13 Sep 2018, 12:49

Hi.
Super nice solution.
Long time I was using way below to get desired special keys

Code: Select all

:?*c:c#:: ; <-- c#		types	ç
SendInput, ç
return
Now I'm using suggestion of Nextron modified even for capital chars

Code: Select all

$*c::
Send {Blind}{c}
KeyWait, c, T0.5
If ErrorLevel {
	If GetKeyState("Shift", "P")
	Send {BackSpace}{Ç}
	else
	Send {BackSpace}{ç}
	KeyWait, c
}
return
This hotkey seems to block all hotstrings beginning with same char. :? Maybe hotkeys are always confusing hotstrings.
As long as the superstrings of Stephen Hawking are not affected, everything is fine. :D
@sulphuricsaliva - I can't give you any suggestion for your new task :crazy:
User avatar
Nextron
Posts: 1391
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: Long press C to send Ç

14 Sep 2018, 11:32

sulphuricsaliva wrote:I'm sorry if I'm pushing it Nextron but would it be possible to add something to the script you gave me so It can send yet another key, depending on how long I press it? Dor instance at the moment if I press c it sends c if I press c for 0.5 sends ç, I wanted to press c for like 0.7 to send A for example. Is it possible?
You could put in another KeyWait, but for me that didn't work very reliable, so try this instead:

Code: Select all

*c::
	If c_remap
		Return
	Send {Blind}{c down}
	c_remap:=A_TickCount
Return

*c up::
	Send {Blind}{c up}
	If (A_TickCount-c_remap>700)
		Send {BackSpace}Long
	Else If (A_TickCount-c_remap>400)
		Send % "{BackSpace}" (GetKeyState("Shift", "P") ? "Ç" : "ç")
	c_remap:=0
Return
I've included divanebaba's addition to enable capital letters. I expected that to happen automatically, but ç is likely sent as a character rather than a key.

divanebaba wrote:This hotkey seems to block all hotstrings beginning with same char. :? Maybe hotkeys are always confusing hotstrings.
Something like that: They're either not seen or ignored. In order to enable that, you need to make sure output is sent using SendEvent and not SendInput, and that the SendLevel is increased. See the code below. I tried to incorporate it in the code above, but I encountered a bug there.

Code: Select all

#InputLevel 1
*c::
	Send {Blind}c
	KeyWait, c, T0.5
	If ErrorLevel
		SendEvent % "{BackSpace}" (GetKeyState("Shift", "P") ? "Ç" : "ç")
	KeyWait, c
return
#InputLevel 0

::çc::Test
DRocks
Posts: 565
Joined: 08 May 2018, 10:20

Re: Long press C to send Ç

14 Sep 2018, 11:48

Wow!! very nice man!!

is this kind of coding able to intercept keys before they get written in specific gui edit controls?
Lets say you want a custom "Number only" "Minus sign/negative value" "commas replaced by dots"?
User avatar
Nextron
Posts: 1391
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: Long press C to send Ç

14 Sep 2018, 12:14

It could, but using a keyboard hook is system wide, so it's like taking a cannon to kill a mosquito. Even then, you could get around it by pasting content or ControlSetText. I think you're better of by using the edit's g-label to set some content validation on each change of the edit box and restoring the last valid content if it contains something not allowed.
DRocks
Posts: 565
Joined: 08 May 2018, 10:20

Re: Long press C to send Ç

14 Sep 2018, 12:22

Nextron wrote:It could, but using a keyboard hook is system wide, so it's like taking a cannon to kill a mosquito. Even then, you could get around it by pasting content or ControlSetText. I think you're better of by using the edit's g-label to set some content validation on each change of the edit box and restoring the last valid content if it contains something not allowed.
Thanks for confirmation! We are trying to do just that with Wolf_II in the thread named "Gui Edit Control Number and decimals..."
thank you for help :)
sulphuricsaliva
Posts: 48
Joined: 11 Sep 2018, 12:37

Re: Long press C to send Ç

20 Sep 2018, 21:00

Ok maybe this last request is probably impossible. Is there a way to long press a key to create dinamic accents. Something like long pressing - to make a tilde (~) that'll be applied to the next letter I press, like a or o to get ã or õ.
User avatar
Nextron
Posts: 1391
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: Long press C to send Ç  Topic is solved

23 Sep 2018, 07:24

There are probably better ways, since this requires you to manually define each of your keys, but it should get you started.

Code: Select all

#UseHook,On
-::
'::
	Send,% A_ThisHotkey
	KeyWait,% A_ThisHotkey,T0.5
	If ErrorLevel {
		Send {BackSpace}
		DeadKey:=A_ThisHotkey
	}
	KeyWait,% A_ThisHotkey
Return

#If DeadKey("'")
o::ó
O::Ó
a::á
#If DeadKey("-")
o::õ
a::ã
#If


DeadKey(Key){
	Global DeadKey
	If _:=(DeadKey=Key)
		DeadKey:=""
	Return _
}
sulphuricsaliva
Posts: 48
Joined: 11 Sep 2018, 12:37

Re: Long press C to send Ç

23 Sep 2018, 11:57

Works perfectly, thank you once more :D
User avatar
divanebaba
Posts: 804
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: Long press C to send Ç

26 Sep 2018, 15:13

To prevent unwanted char when pressing Ctrl + c key I choosed this way

Code: Select all

...
Send % (GetKeyState("Ctrl", "P") ? "^c" : GetKeyState("Shift", "P") ? "{BackSpace}Ç" : "{BackSpace}ç")
...
How to use SendEvent or SendLevel to prevent hotstrings by using this code I could not realize.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], tiska and 100 guests