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
Have different "modes" to change the output of a key
Re: Have different "modes" to change the output of a key
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%
Re: Have different "modes" to change the output of a key
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.
Naturally you could have other modes (2,3) etc.
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
Re: Have different "modes" to change the output of a key
Thanks,
This worked perfectly for my needs!
This worked perfectly for my needs!
Re: Have different "modes" to change the output of a key
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.
Re: Have different "modes" to change the output of a key
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.
Re: Have different "modes" to change the output of a key
Very strange, I had this Always on Top script
above the 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!
Code: Select all
; Always on Top CTRL+SPACE
^SPACE:: Winset, Alwaysontop, , A
Code: Select all
mode :=1
Thanks for making me retest the original code to figure out the problem!
Re: Have different "modes" to change the output of a key
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).Miah wrote: ↑16 Sep 2021, 11:31Very strange, I had this Always on Top scriptabove theCode: Select all
; Always on Top CTRL+SPACE ^SPACE:: Winset, Alwaysontop, , A
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.Code: Select all
mode :=1
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.
Re: Have different "modes" to change the output of a key
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:
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")
Code: Select all
mode := 1, ComObjCreate("SAPI.SpVoice").Speak("hotkeys cocked and loaded",1)
Re: Have different "modes" to change the output of a key
You need to assign it to an object and then invoke the speech when referencing that object. Demonstrated:
vs.:
Code: Select all
oSpeech := ComObjCreate("SAPI.SpVoice")
oSpeech.Speak("hotkeys cocked and loaded", 1)
MsgBox, It's speaking while this is being displayed.
Code: Select all
ComObjCreate("SAPI.SpVoice").Speak("hotkeys cocked and loaded", 1)
MsgBox, There is no asynchronous speech in this case.
Re: Have different "modes" to change the output of a key
That's what I was missing! Thanks so much, you rock!!!
Who is online
Users browsing this forum: Rohwedder and 185 guests