How can I use the + keystroke in a hotkey?

Get help with using AutoHotkey and its commands and hotkeys
Posts: 1
Joined: 24 Apr 2019, 16:43

How can I use the + keystroke in a hotkey?

24 Apr 2019, 17:22

I use lots of subscripts and scripts. For example H₂O, Ca⁺², X², CaH₍₂₋ₓ₎ etc. I can make numeric and some symbols as subscripts and superscripts using unicode similar to the following code but I have found no way to capture the + symbol to generate the + superscript. How can I capture the + keystroke as I type to generate the unicode ⁺?

<!2:: ; left alt + 2 creates 2 subscript
send ₂
<!(:: ; left alt + ( creates ( subscript
send ₍
>!2:: right alt + 2 creates 2 superscript
send ²
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: How can I use the + keystroke in a hotkey?

24 Apr 2019, 19:47

I'm not entirely certain of what you're doing, but I imagine that using the VK code of the key would solve your problem. The VK code for the + key is vkBB. You can make a hotkey for it by doing vkBB:: or, if you're reading input, you may need to use the GetKeyVK() function to know when it's encountered.

The TooltipKeypress script is very helpful for discovering key codes by running it or just looking at the scripting to see how to do a handle input:

Code: Select all

CoordMode, ToolTip, Screen
SetFormat, IntegerFast, H

CleanTimer := -3000	; Must be a negative number (the timer will run only once)

Loop, 5000
  Hotkey, % "~*" GetKeyName(Format("vk{:x}", a_index - 1)), GetText
  Hotkey, % "~*" GetKeyName(Format("sc{:x}", a_index - 1)), GetText
  ; "~" keeps the button original function
  ; "*" fires the hotkey even if extra modifiers are being held down

Gui, New, -MinimizeBox
Gui, Add, Edit, w200 h100,
Gui, Show

  SetTimer, CleanText, Off
  Sleep, 50
  Key := RegExReplace(A_ThisHotkey, "^..")    	; "^.." removes the first 2 characters ("~*") from the returned string
  KeyVK := GetKeyVK(Key)
  KeyVK := RegExReplace(KeyVK, "^..")
  KeySC := GetKeySC(Key)
  KeySC := RegExReplace(KeySC, "^..")
  Text .= Key
  ToolTip, % "Key Name: {" Key "}`nKey VK: {vk" KeyVK "}`nKey SC: {sc" KeySC "}`n`n" Text, 0, 0  ; X\Y coordinates
  SetTimer, CleanText, %CleanTimer%

  Text := ""


Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], flyingDman, jp94189 and 216 guests