Combine multiple numeric hotkeys into one

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Nixcalo
Posts: 116
Joined: 06 Feb 2018, 04:24

Combine multiple numeric hotkeys into one

Post by Nixcalo » 14 Sep 2023, 20:51

I want to write ❶ (Unicode+2776) when I press AltGr+1, ❷ (Unicode+2777) when I press AltGr+2, and so on.

Is there a way to do it that is neater than this:

Code: Select all

#1::
#2::
#3::
#4::
#5::
#6::
#7::
#8::
#9::

Code:=0x2776 ;+Base in hexadecimal, corresponds to character ❶
Code+=HotkeyNumber-1 ; Adds pressed number to Code and substracts 1 to get the value of  ❶-❾
Code:=Format("{:X}", Code) ; Transforms Code to hex
SendInput, {U+%Code%} ; Pastes as character carácter ❶-❾
Return
[Mod edit: [code][/code] tags added. Please use them yourself in future posts.]

I am sure there must be.. or we really have to code 9 hotkeys for the 9 digits? I am sure there must be also a way to shorten the rest of the code, more elegantly. I have had problems adding up two hexadecimal numbers, hence the Format line.

Any ideas?

off
Posts: 176
Joined: 18 Nov 2022, 21:54

Re: Combine multiple numeric hotkeys into one

Post by off » 14 Sep 2023, 20:59

Hello!
This is my first approach:

Code: Select all

Code:=0x2776 ;+Base in hexadecimal, corresponds to character ❶
#1::
#2::
#3::
#4::
#5::
#6::
#7::
#8::
#9::
Key := Format("{:X}", Code + StrReplace(A_ThisHotkey, "#") - 1) ; Transforms Code to hex
SendInput, {U+%Key%} ; Pastes as character carácter ❶-❾
Return
My Creations
IMG2HotString - Send image file easily with your hotstring!
CtrlSend - A small solution for sending keys to window in background that doesn't accept ControlSend's key
ControlProcess

User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Combine multiple numeric hotkeys into one

Post by mikeyww » 14 Sep 2023, 21:08

Code: Select all

#Requires AutoHotkey v1.1.33

<^>!1::
<^>!2::
<^>!3::
<^>!4::
<^>!5::
<^>!6::
<^>!7::
<^>!8::
<^>!9::Send % Format("{U+{:X}}", 0x2775 + SubStr(A_ThisHotkey, 0))

Post Reply

Return to “Ask for Help (v1)”