Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Request: Shift+a gives ( á â ä)



  • Please log in to reply
6 replies to this topic
Artie
  • Members
  • 12 posts
  • Last active: Dec 15 2015 07:26 AM
  • Joined: 21 Aug 2015

Can you guys help me write a script that types special characters (à,á,â,ä) and (è,é,ê,ë) by the following method:

  • If I press (Shift+a), it gives me à. (instead of A)
  • If I press (Shift+a), it gives me à, and press a again (while still holding Shift), it gives á, a third time gives â, fourth time gives ä, and a fifth time goes back to à, and so on.
  • If I release Shift, I type normally.
  • Every time I release Shift, then hold it again +a, it starts with the first one, which is à.
  • Same thing for e with (è,é,ê,ë).

So for example, if I want to type "déjà",

  1. d
  2. Shift+ee (twice e)
  3. j
  4. Shift+a

I hope you guys can help me with this script, as I don't have much experience coding.

Thank you.



Exaskryz
  • Members
  • 3249 posts
  • Last active: Nov 20 2015 05:30 AM
  • Joined: 23 Aug 2012

This isn't the full script you want, but something to get you started. All code is untested though, so I apologize for any mistakes.

 

Note: Save your script as Unicode (Encoding should be UTF-8) just to make sure the characters come through correctly. If you don't have a Unicode version of AHK, we can still work through it.

 

+a::
Send à
KeyWait, a ; Wait for you to release a before moving on
If !GetKeyState("Shift","P") ; if you have released the shift key, GetKeyState() returns 0; the ! means "NOT". "NOT-Zero" is considered true, and will execute the return line below and end this thread.
    return
KeyWait, a, d t2 ; press the a key.  This command will time-out in 2 seconds
If ErrorLevel ; if the line above timed out
    return
If !GetKeyState("Shift","P") ; If this thread is still running but you released shift, we'll send a normal "a" character
    {
    Send a
    return
    }
Send {BackSpace} á
KeyWait, a ; Wait for you to release a before moving on
If !GetKeyState("Shift","P") ; if you have released the shift key, GetKeyState() returns 0; the ! means "NOT". "NOT-Zero" is considered true, and will execute the return line below and end this thread.
    return
KeyWait, a, d t2 ; press the a key.  This command will time-out in 2 seconds
If ErrorLevel ; if the line above timed out
    return
If !GetKeyState("Shift","P") ; If this thread is still running but you released shift, we'll send a normal "a" character
    {
    Send a
    return
    }
return

 

The key features are KeyWait, GetKeyState, and the logical-NOT operator (!). If is in there too.

 

Advanced code below. You may understand it, but as you said you have little coding experience, I don't think that's the best one to demonstrate for ya. But it should technically be the easiest to update and adapt because it's much shorter code.

Spoiler


Artie
  • Members
  • 12 posts
  • Last active: Dec 15 2015 07:26 AM
  • Joined: 21 Aug 2015

Thank you Exaskryz. I tested both of them but they don't function properly. I have an older script that was given to me by someone from this site but it does it in a different way.

Akeys:=["a","à","â","ä"],
EKeys:=["e","è","é","ê"],
$*a::
$*e::

Hotkey:=SubStr(A_ThisHotkey,0)
While GetKeyState(Hotkey,"P"){
	If A_Index>1
		Send {BS}
	for k,key in %hotkey%keys
	{
		If A_Index>1
			Send {BS}
		Send % "{Blind}" key
		Loop 20 {
			Sleep 50
			If !GetKeyState(Hotkey,"P")
				break, 2
		}
	}
}
return

When I hold on a , it waits a moment and then gives à, then â in its place, then ä and so on, until I stop at the character that I want. In that way, only one character has been typed, and no spaces either, making typing with special characters easy. However I realized it is not very fast. Instead of the wait, I wanted that I can shuffle through all the a variants by holding shift and tapping a as fast as I like, until I get what I want.

The script above does so the following things exactly right:

  • As long as I'm holding the key, all previous characters are deleted.
  • There is no space after the character that I finally choose. (I still don't know how that worked)


Exaskryz
  • Members
  • 3249 posts
  • Last active: Nov 20 2015 05:30 AM
  • Joined: 23 Aug 2012

Edit: Incidental double post.



Exaskryz
  • Members
  • 3249 posts
  • Last active: Nov 20 2015 05:30 AM
  • Joined: 23 Aug 2012

I have no idea what is wrong with my idea and code. I tried changing some of the If GetKeyState()'s to check both the LShift and RShift states, but it's choppy. The second code kind of worked, but it had a really tough time counting to three and I had to spam the a key fast while also holding LShift and spam pressing the RShift key to get it to count to three....... So IDK...

Wait... I came up with this code:

a_array:=["à","á","â","ä"]
;a_array:=["b","c","d","e"]
$+a::
If (A_PriorHotkey=A_ThisHotkey)
{
n++
If n=5
n:=1
Send {backspace}
Send % a_array[n]
}
else
{
n:=1
Send % a_array[n]
}
return

And when I didn't have the $, there were problems. The accented 'a' keys that AHK was producing were triggering the hotkey again, which was one of the problems... So, here's my original attempt with corrections. I think it's working better now.

a_array:=["à","á","â","ä"]
$+a::
While GetKeyState("LShift","P") || GetKeyState("RShift","P")
{
number:=(!(x:=Mod(A_Index,4))?4:x)
Tooltip % number
If A_Index>1
Send {Backspace}
Send % a_array[number]
KeyWait, a
KeyWait, a, d t2
If ErrorLevel
   Break
}
return

If you still want it to cycle through just by holding Shift in addition to being able to jump forward, remove the If ErrorLevel and Break lines.

 

My long-form code with the many many KeyWait and If GetKeyState()'s also had an error of using Send {Backspace} á which should have been Send {Backspace}á.

 

Edit: The previous code you shared looks like it needs to have several changes to get it to work for shift-only. I, or someone more competent than me, can try modifying that code if you'd prefer.



Xtra
  • Members
  • 954 posts
  • Last active: Jul 23 2016 09:04 PM
  • Joined: 29 Sep 2013
✓  Best Answer
$+a::
$+e::
    keys(SubStr(A_ThisHotkey,0))
return


keys(k)
{   ; remove a and e if you dont want A or E in the rotation.
    static A:=["a","à","á","â","ä"],E:=["e","è","é","ê","ë"]
    c:=0    ; counter resets on every use.
    While GetKeyState("Shift","P")
    {
	If GetKeyState(k,"P")
	{
            Send % "{Blind}" (A_Index>1?"{BS}":"") %k%[(c=%k%.MaxIndex())?c:=1:++c]
	    KeyWait, % k
	}
	Sleep 50
    }
}

Try this function.



Artie
  • Members
  • 12 posts
  • Last active: Dec 15 2015 07:26 AM
  • Joined: 21 Aug 2015

Ahh yes!, Thank you so much Xtra, it works exactly how I wanted.