Mapping number keys to numpad

Get help with using AutoHotkey and its commands and hotkeys
Llaves
Posts: 3
Joined: 08 Aug 2020, 16:45

Mapping number keys to numpad

08 Aug 2020, 17:03

My laptop doesn't have a keypad so I can't enter special char sequences like Alt-0176 to enter the degree symbol. I can map the numeric keys (ie, top row of normal keyboard) to the keypad with
0::numpad0
1::numpad1

and so on. However, if I do this, I lose the shift characters on the numeric keys.
So my next attempt was to map the numeric keys with a modifier -
^0::numpad0
^1::numpad1
and so on.

Typing ^0 produces nothing (same for all other keys)

Next attempt -
0::numpad0
+0:: send !

This doesn't work either.

Why don't modifiers work on numeric keys? And how do I achieve my goal of having numbers appear to be typed on the keypad while shift-number is the special char above the number?
Thanks
User avatar
flyingDman
Posts: 841
Joined: 29 Sep 2013, 19:01

Re: Mapping number keys to numpad

08 Aug 2020, 18:17

This is one way to deal with it. Assign a hotkey to this. Enter the code and press enter.

Code: Select all

InputBox,oVar,Enter alt sequence,,,200,100
send {Lalt down}
for x,y in strsplit(oVar)
	send {Numpad%y%}
send {Lalt up}
return
Or you can use Hotstrings() (see here: https://github.com/Paris/AutoHotkey-Scripts/blob/master/Hotstrings.ahk)

Code: Select all

hotstrings("(\d+)alt", "label")
return

label:
send {Lalt down}
for x,y in strsplit($1)
	send {Numpad%y%}
send {Lalt up}
return
This would allow you to use any code followed by the letters "alt" to produce the desired ascii character.
Llaves
Posts: 3
Joined: 08 Aug 2020, 16:45

Re: Mapping number keys to numpad

08 Aug 2020, 18:54

thanks for the help.
I modified your first suggestion to bind the call to inputbox to ctrl-sh-a:

Code: Select all

^+a::

InputBox,oVar,Enter alt sequence,,,200,100
send {Lalt down}
for x,y in strsplit(oVar)
	send {Numpad%y%}
send {Lalt up}
return
I couldn't make your second example work. I get and error that hotstrings() is not defined, so I changed that to Hotstring. Now I get an error on the first parameter. So I changed that to "::(\d+)alt". Now the script loads without errors, but when I type "0176alt" in an editor, nothing happens.
User avatar
flyingDman
Posts: 841
Joined: 29 Sep 2013, 19:01

Re: Mapping number keys to numpad

08 Aug 2020, 19:14

Hotstrings() is a function (and it is hotstrings() not hotstring()). You need to define it in your script or include it in a Library.
Rather than simulating alt XXX keystroke combinations, you should use Chr().

Code: Select all

hotstrings("(\d+)alt", "label")
return

label:
send % chr($1)
return
and

Code: Select all

InputBox,oVar,Enter alt sequence,,,200,100
send % chr(oVar)
return
Llaves
Posts: 3
Joined: 08 Aug 2020, 16:45

Re: Mapping number keys to numpad

08 Aug 2020, 22:09

got it. I missed that hotstrings was a user-defined function that has to be in the script or library.

Return to “Ask For Help”

Who is online

Users browsing this forum: AHKStudent, Bing [Bot], Lukunka, mabohango, mikeyww, PlumpSamurai and 43 guests