Help with simple IF instructions.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
bobkater
Posts: 22
Joined: 10 Nov 2019, 08:42

Help with simple IF instructions.

Post by bobkater » 26 Jul 2021, 06:56

Can somebody give me the AHK instructions for achieving the following conditional requirement:

If I press key : ; (scan code 027)
then execute set of instructions A (which I have)

If (instead) I press key CapsLock (scan code 03A)
then execute set of instructions B (which I also have)

Thanks in advance.
gregster
Posts: 8886
Joined: 30 Sep 2013, 06:48

Re: Help with simple IF instructions.

Post by gregster » 26 Jul 2021, 07:05

These requirements sound like normal hotkeys, no If required:

Code: Select all

:::
msgbox this is the : Hotkey
; more code
Return

Capslock::
msgbox this is Capslock
; more code
return
bobkater
Posts: 22
Joined: 10 Nov 2019, 08:42

Re: Help with simple IF instructions.

Post by bobkater » 26 Jul 2021, 08:05

Thanks for the quick response gregster.
As you would have guessed I’m not much good at this and I’m doing something wrong.

So each of the set of instructions A and B works on its own, namely:

set A

Code: Select all

:::
sc027::var := "´"
#if (var = "´"), var := ""
e::Send, é
+e::Send, É
Return
set B

Code: Select all

Capslock::
sc03A::var := "´"
#if (var = "´"), var := ""
e::Send, è
+e::Send, È
return
[Mod edit: [code][/code] tags added.]

But when I try to putt them one after the other (i.e. B after A) on the same script, it gives me error about duplicate key e.

What am I doing wrong?
gregster
Posts: 8886
Joined: 30 Sep 2013, 06:48

Re: Help with simple IF instructions.

Post by gregster » 26 Jul 2021, 09:41

So I guess you are looking for some kind of three-way toggle... sorry, I couldn't derive that from your original request.
There are different ways to achieve this, depending on what you actually want:

Code: Select all

sc027::toggle := (toggle = 1) ? 0 : 1		; press : 
sc03A::toggle := (toggle = 2) ? 0 : 2		; press Capslock

#if (toggle = 1)
e::Send, é
+e::Send, É
#if

#if (toggle = 2)
e::Send, è
+e::Send, È
#if
: has a different scan code on my keyboard layout (did you try ::: instead ? ), but if you say sc027 is the key on yours, use that.

If you want something else, please elaborate.

Edit: Based on your scripts above, I assume that only one (the very next) e/E character should be modified. One way:

Code: Select all

sc027::toggle :=  1			; press : 
sc03A::toggle :=  2			; press Capslock

#if !((toggle = 1) ? (toggle := 0) : 1) 
e::Send, é
+e::Send, É
#if

#if !((toggle = 2) ? (toggle := 0) : 1)
e::Send, è
+e::Send, È
#if
bobkater
Posts: 22
Joined: 10 Nov 2019, 08:42

Re: Help with simple IF instructions.

Post by bobkater » 26 Jul 2021, 11:34

As trying your method will take me some time, I make this preliminary post to thank you again – in fact I remember you also helping me in the past. I’ll come back with feedback after the trial.

Now, since you got involved, I’ll describe better what I’m trying to do:
The idea is to first press a preparatory key as modifier and then the key of the letter that I want modified.
My scripts A and B put the French accents aigu or grave on letter e by first pressing the preparatory key : (which is SC027 on my keyboard) or CapsLock respectively, and then e.

But in fact, I use this method to put accents and cedille on the remaining French letters, so sets A and B are much longer, but simplified them to only the letter e for easier explanation.
I further intend to extend the script to include a third preparatory key, namely Tab, for placing the circumflex accent (the one that looks like a pointed hat).

So the idea is not to simply put the two accents on the letter e, but to conditionally arrange for the execution of one of two (actually three) sets of instructions according to which preparatory key I press, and ignore the other sets to avoid duplicated letter errors.
I’ll thus be able to do any modification to any letter by preceding it with the appropriate preparatory key.

I hope the above makes sense and I am at your disposal for clarifications, if you want.
gregster
Posts: 8886
Joined: 30 Sep 2013, 06:48

Re: Help with simple IF instructions.

Post by gregster » 26 Jul 2021, 11:46

I see - then I guess the code in the second box should do what you want.
Adding more keys should also be possible with it.
bobkater
Posts: 22
Joined: 10 Nov 2019, 08:42

Re: Help with simple IF instructions.

Post by bobkater » 26 Jul 2021, 13:27

Success!!!
Vielen Dank, du hast mir sehr geholfen (ich erinnere mich vom letzten mal daran, dass du Deutch bist).

Yes, the code in the second box seems to do exactly what I want, at least I couldn’t find a bug so far.

Also compliments on understanding what on earth I was talking about in my previous post. :)

So, also for possibly helping others, I give below the full script using 3 different preparatory keys: ;, CapsLock and Tab that respectively put the French accents: aigu (or cedille), grave and circumflex (once) on the letters pressed after them.

Code: Select all

sc027::toggle :=  1			; press : 
sc03A::toggle :=  2			; press Capslock
sc00F::toggle :=  3			; press Tab

#if !((toggle = 1) ? (toggle := 0) : 1) 
e::Send, é
c::Send, ç
+e::Send, É
+c::Send, Ç
#if

#if !((toggle = 2) ? (toggle := 0) : 1)
a::Send, à
e::Send, è
u::Send, ù
+a::Send, À
+e::Send, È
+u::Send, Ù
#if

#if !((toggle = 3) ? (toggle := 0) : 1) 
a::Send, â
e::Send, ê
i::Send, î
o::Send, ô
u::Send, û
+a::Send, Â
+e::Send, Ê
+i::Send, Î
+o::Send, Ô
+u::Send, Û
#if
Last edited by bobkater on 26 Jul 2021, 13:32, edited 1 time in total.
gregster
Posts: 8886
Joined: 30 Sep 2013, 06:48

Re: Help with simple IF instructions.

Post by gregster » 26 Jul 2021, 13:30

Gern geschehen. :thumbup: Happy to help!
Post Reply

Return to “Ask for Help (v1)”