Have different "modes" to change the output of a key

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
max25671
Posts: 2
Joined: 03 Sep 2017, 13:51

Have different "modes" to change the output of a key

03 Sep 2017, 14:01

Hello,
I am trying to create a script that allows my three-pedal foot pedal to have multiple different keystrokes. So for example, I press "pedal 1" and it will output the number "1" . But if I press a key on my keyboard (one of the function keys) it will change the keystroke of "pedal 1" to "4". Then I press the same function key again, and it will make "pedal 1" output "1". Is this possible, I'm quite new to AHK.
Thanks,
Max
User avatar
boiler
Posts: 16903
Joined: 21 Dec 2014, 02:44

Re: Have different "modes" to change the output of a key

03 Sep 2017, 15:17

Have your foot pedal send a key that you wouldn't use otherwise, like shift-control-F10. That will just be a "middleman" that will be used to trigger sending the output you actually want. For example, if you wanted the F1 key to have your foot pedal send "1" (the default) and your F2 key to have the foot pedal send "4":

Code: Select all

PedalText := "1"
F1::PedalText := "1"
F2::PedalText := "4" 
+^F10::Send, %PedalText%
Noesis
Posts: 301
Joined: 26 Apr 2014, 07:57

Re: Have different "modes" to change the output of a key

04 Sep 2017, 01:06

The main thing here is to have each pedal function mapped to something that will be recognized by ahk, like boiler said. However, since there are 3 pedals (that's how I'm reading your OP) rather than do it exactly like boiler is saying (which would work for a single pedal, and could be made to work using an array with multiple pedals) an alternative method, which may be simpler to understand or preferred depending on the level of control needed is as follows.

Code: Select all

PedalMode := 1
F1::PedalMode := 1
F2::PedalMode := 4

#If (PedalMode = 1)
+^F10::Send, 1	; Pedal 1
+^F11:: Send, 2 ; Pedal 2
+^F12:: Send, 3 ; Pedal 3
#If
#If (PedalMode = 4)
+^F10::Send, 4	; Pedal 1
+^F11:: Send, 5 ; Pedal 2
+^F12:: Send, 6 ; Pedal 3
#If
Naturally you could have other modes (2,3) etc.
max25671
Posts: 2
Joined: 03 Sep 2017, 13:51

Re: Have different "modes" to change the output of a key

04 Sep 2017, 06:54

Thanks,
This worked perfectly for my needs!
Miah
Posts: 6
Joined: 15 Sep 2021, 18:13

Re: Have different "modes" to change the output of a key

16 Sep 2021, 08:05

Noesis wrote:
04 Sep 2017, 01:06

Code: Select all

PedalMode := 1
How do you set PedalMode := 1 by default on start? I assume that's what this code was meant to do, but it's not working for me.

The rest works great, thanks for that!

Sorry to dig up such an old post, but this was exactly what I needed except the default not being set on startup.
User avatar
boiler
Posts: 16903
Joined: 21 Dec 2014, 02:44

Re: Have different "modes" to change the output of a key

16 Sep 2021, 08:29

That is what it does. What is happening that makes you think it is not set? Can you post your entire script as you ran it? Please post it between [code][/code] tags.
Miah
Posts: 6
Joined: 15 Sep 2021, 18:13

Re: Have different "modes" to change the output of a key

16 Sep 2021, 11:31

Very strange, I had this Always on Top script

Code: Select all

; Always on Top CTRL+SPACE
^SPACE::  Winset, Alwaysontop, , A	
above the

Code: Select all

mode :=1
which was making it not trigger, but when I put it under it, it works fine. Not sure why that is, but it seems to be working this way.

Thanks for making me retest the original code to figure out the problem!
gregster
Posts: 8992
Joined: 30 Sep 2013, 06:48

Re: Have different "modes" to change the output of a key

16 Sep 2021, 11:36

Miah wrote:
16 Sep 2021, 11:31
Very strange, I had this Always on Top script

Code: Select all

; Always on Top CTRL+SPACE
^SPACE::  Winset, Alwaysontop, , A	
above the

Code: Select all

mode :=1
which was making it not trigger, but when I put it under it, it works fine. Not sure why that is, but it seems to be working this way.
Well, at the top of the script, there is the auto-execute section, which gets executed at script start - but it ends automatically at the first hotkey (among other things).
Please compare https://www.autohotkey.com/docs/Scripts.htm#auto
By placing that line below the hotkey, you made it unreachable, and it never got executed.
Miah
Posts: 6
Joined: 15 Sep 2021, 18:13

Re: Have different "modes" to change the output of a key

16 Sep 2021, 11:45

Gotcha. I doubt it's related; but I am also trying to get it to speak on startup and when I change modes, which is working, but when I run it my hotkeys won't work until it's done talking. For example this works:

Code: Select all

mode := 1, ComObjCreate("SAPI.SpVoice").Speak("hotkeys cocked and loaded")
but this doesn't (which is what I thought others said enabled the asynchronous mode):

Code: Select all

mode := 1, ComObjCreate("SAPI.SpVoice").Speak("hotkeys cocked and loaded",1)
User avatar
boiler
Posts: 16903
Joined: 21 Dec 2014, 02:44

Re: Have different "modes" to change the output of a key

16 Sep 2021, 14:56

You need to assign it to an object and then invoke the speech when referencing that object. Demonstrated:

Code: Select all

oSpeech := ComObjCreate("SAPI.SpVoice")
oSpeech.Speak("hotkeys cocked and loaded", 1)
MsgBox, It's speaking while this is being displayed.
vs.:

Code: Select all

ComObjCreate("SAPI.SpVoice").Speak("hotkeys cocked and loaded", 1)
MsgBox, There is no asynchronous speech in this case.
Miah
Posts: 6
Joined: 15 Sep 2021, 18:13

Re: Have different "modes" to change the output of a key

16 Sep 2021, 15:55

That's what I was missing! Thanks so much, you rock!!! :bravo:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: haomingchen1998, mikeyww, mmflume, roysubs, scriptor2016, ShatterCoder and 103 guests