? Morse style input using NumPad hotkeys and loop command

Get help with using AutoHotkey and its commands and hotkeys
User avatar
iilabs
Posts: 179
Joined: 07 Jun 2020, 16:57

? Morse style input using NumPad hotkeys and loop command

Post by iilabs » 22 Jan 2021, 23:04

Hi everyone,

How would I go about making hotkeys using my numpad. This is what I tried but maybe not understanding the logic. Maybe a better way? Thanks all.

This was adopted from a previous post from Laszlo!
https://autohotkey.com/board/topic/15574-morse-find-hotkey-press-and-hold-patterns/

The timeout works fine.

Code: Select all

;//////////Morse
Morse(timeout = 400) { ;
   tout := timeout/1000
   key := RegExReplace(A_ThisHotKey,"[\*\~\$\#\+\!\^]")
   Loop {
      t := A_TickCount
      KeyWait %key%
      Pattern .= A_TickCount-t > timeout
      KeyWait %key%,DT%tout%
      If (ErrorLevel)
         Return Pattern
        }
     }
The second part does NOT work but I would rather not make one for each Numpad key and each label. I am not sure how to use the for loop to make that x variable go preferably from 0 to 9?

Code: Select all


; Loop for Numpad Hotkeys
x:=0
while(x<10)
{
x++
Hotkey, Numpad[x], MyLabel[x]
Mylabel[x]:
   p := Morse()
   If (p = "0")
        {
		side := sideA[x]
        degree := degreeA[x]
		Gosub, MeatA[x]
		}
   Else If (p = "00")
        {
		side := sideB[x]
        degree := degreeB[x]
        Gosub, MeatB[x]
		}
	Else If (p = "01")
		{
        side := sideB[x]
        degree := degreeB[x]
        Gosub, MeatC[x]
		}
	Else If (p = "011") ;Short+Long press+long press
		{
        MsgBox, NOT SET
		}
	Else
        MsgBox, Press pattern %p%
Return
}



; loop for sending sandwich
a:=0
while(a<10) {
a++
MeatA[a]: 
Sendinput, %degree% %side% MeatA%a%
Return
}

b:=0
while(b<10) {
b++
MeatB[b]:
Sendinput, %degree% %side% MeatB%b%
Return
}

c:=0
while(c<10) {
c++    
MeatC[c]:
Sendinput, %degree% %side% MeatC%c%
Return
}++
MeatB%b%:
Sendinput, %degree% %side% MeatB%b%
Return
}

c:=0
while(c<10) {
c++    
MeatC[c]:
Sendinput, %degree% %side% MeatC%c%
Return
}

Last edited by iilabs on 23 Jan 2021, 15:39, edited 1 time in total.
Rohwedder
Posts: 3982
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: ? Morse style input using NumPad hotkeys and loop command

Post by Rohwedder » 23 Jan 2021, 02:17

Hallo,
just describe what you want your script to do!
User avatar
iilabs
Posts: 179
Joined: 07 Jun 2020, 16:57

Re: ? Morse style input using NumPad hotkeys and loop command

Post by iilabs » 23 Jan 2021, 15:30

Hi and thanks for reply! I actually have seen some of your work on the help forums and very useful.

Basically I'm trying to make a sentence builder using Numpad and pseudo morse. I realized maybe I need to make an array so modified the code above with [] but not sure if I did that correctly.

So for example, if I want to say,

"I would like a hot turkey sandwich with tomatoes."

I would use a single key press to store variable %single% for the first identifier; cold, hot, spicy etc on numpad0-9
Double press for changing a second variable %double% in the sentence like turkey, roastbeef, pastrami, etc
Long press for the third variable %long% for lettuce, tomatoes, pickles, onions, etc

I would like" %single% %double% "sandwich with" %long% as those numpads are being pressed.
Rohwedder
Posts: 3982
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: ? Morse style input using NumPad hotkeys and loop command

Post by Rohwedder » 24 Jan 2021, 08:51

Maybe this will help you with your sandwich:

Code: Select all

Loop, 10
	Hotkey,% "Numpad" (A_Index-1), MyLabel
Return

MyLabel:
x := SubStr(A_ThisHotkey,0)
P := Morse()
ToolTip,% "x: " x "`nP: " P
Return

Morse(timeout = 400)
{ ;https://autohotkey.com/board/topic/15574-morse-find-hotkey-press-and-hold-patterns/
	tout := timeout/1000
	key := RegExReplace(A_ThisHotKey,"[\*\~\$\#\+\!\^]")
	Loop
	{
		t := A_TickCount
		KeyWait %key%
		Pattern .= A_TickCount-t > timeout
		KeyWait %key%,DT%tout%
		If (ErrorLevel)
			Return Pattern
	}
}
Instead of If, else I would use Switch, Case
https://www.autohotkey.com/docs/commands/Switch.htm
User avatar
iilabs
Posts: 179
Joined: 07 Jun 2020, 16:57

Re: ? Morse style input using NumPad hotkeys and loop command

Post by iilabs » 24 Jan 2021, 10:16

Ok great! Thank you for your tome. Awesome I always wanted to learn the switch case. Will let you know. Forgot to add the beer to the mix! Cheers! :beer:
Post Reply

Return to “Ask For Help”