Can an exclamation mark be used as hotkey?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ndiaz
Posts: 73
Joined: 10 Jan 2017, 17:05
Contact:

Can an exclamation mark be used as hotkey?

18 Apr 2019, 11:39

For an autocorrect string where the exclamation mark is replaced with non-breaking space + exclamation mark, how can the exclamation mark, being the modifier for Alt be used as a hotkey?
gregster
Posts: 9047
Joined: 30 Sep 2013, 06:48

Re: Can an exclamation mark be used as hotkey?

18 Apr 2019, 12:21

Either there is something to modify, then ! is a modifier - or there is nothing to modify, then ! is a !:

Code: Select all

!::msgbox
If you want to remap Alt alone, then you can use:

Code: Select all

alt::msgbox alt
Finally, Alt + !

Code: Select all

!!::msgbox
ndiaz
Posts: 73
Joined: 10 Jan 2017, 17:05
Contact:

Re: Can an exclamation mark be used as hotkey?

18 Apr 2019, 12:30

Thank you! I had just realized that before reading your reply. My intended hotstring wasn't working for other reasons, not because of a bad abbreviation. And thank you for the additional explanations regarding Alt, very helpful!

Another head-scratcher was trying to use a colon as the abbreviation for a hotstring. I couldn't figure how to make it work so I ended up using this:

Code: Select all

: up::Send ^+{Space}:
But I'm still wondering if it could be done with a hotstring.
gregster
Posts: 9047
Joined: 30 Sep 2013, 06:48

Re: Can an exclamation mark be used as hotkey?

18 Apr 2019, 12:38

This works for me with a hotstring:

Code: Select all

::!up::Hello world
It seems you are missing a :

Or, do want to replace a string with : ?

Code: Select all

::colon:::		; replaces "colon" with ":"
But if you want to use a command like Send in a one-line-hotstring, you need to use the X option (AHK version 1.1.28+):

Code: Select all

:X:colon::Send :
ndiaz
Posts: 73
Joined: 10 Jan 2017, 17:05
Contact:

Re: Can an exclamation mark be used as hotkey?

18 Apr 2019, 13:22

Thank you gregster,

The intended action is to add a non-breaking space (achieved by pressing Ctrl+Alt+Space) before a colon, immediately when typing ":".

But I didn't know how to use ":" as the abbreviation for a hotstring, so my workaround was to use the up state of ":" as a hotkey instead, which is working.
lexikos
Posts: 9599
Joined: 30 Sep 2013, 04:07
Contact:

Re: Can an exclamation mark be used as hotkey?

18 Apr 2019, 20:22

The hotkey and hotstring parsers have some trouble with ":". You can create a hotstring with ":" as the trigger by using the Hotstring function in v1.1.28+.

Code: Select all

Hotstring(":*::", Func("nbsp_colon"))
nbsp_colon() {
    Send ^+{Space}:
}
You can create a ":" hotkey without doing anything special:

Code: Select all

:::MsgBox colon
However, you probably want to do this:

Code: Select all

:::Send ^+{Space}:
...but that will probably create a loop where the sent colon triggers the hotkey. To avoid that, you might want to add the $ prefix:

Code: Select all

$:::Send ^+{Space}:
...but that won't work because the hotkey parser doesn't support it. So you can do this instead:

Code: Select all

$+;::Send ^+{Space}:
...but that will only work with keyboard layouts where Shift+; produces ":", such as the US layout. Instead, you can use the Hotkey command or #UseHook:

Code: Select all

Hotkey $:, nbsp_colon  ; Passing a function requires v1.1.20+
nbsp_colon() {
    Send ^+{Space}:
}

Code: Select all

#UseHook
:::Send ^+{Space}:
The hotkey is mapped according to the script's keyboard layout (usually the system default layout), so if the system has multiple layouts with different ways of producing ":", a hotkey will only work with the "default" way while a hotstring will adapt to the active window.
ndiaz
Posts: 73
Joined: 10 Jan 2017, 17:05
Contact:

Re: Can an exclamation mark be used as hotkey?

19 Apr 2019, 10:28

Excellent information, thank you!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Darkmaster006, mikeyww, Raghava Doregowda and 346 guests