Sending strings with Numpad events; literals

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
melds
Posts: 2
Joined: 20 Apr 2021, 17:11

Sending strings with Numpad events; literals

20 Apr 2021, 17:46

Hello,

First, when using a Numpad hotkey that requires the shift key, the output is shifted. However, other shifted keys work fine.

Hitting shift-Numpad1 results in an all-caps output:

Code: Select all

NumpadEnd::
Send, hello world
return
HELLO WORLD
Hitting shift-4 for the dollar sign outputs as expected:

Code: Select all

$::
Send, hello world
return
hello world
Is there a way to have this output not being affected while using the shifted numpad events?

Second, I was wondering if there's a way to output a literal string that contains special characters without having to escape them. In some programming languages you can use single quotes, but that doesn't seem to help. The following fail:

Code: Select all

^1::
Send, hello%world
return

^1::
Send, "hello%world"
return

^1::
Send, 'hello%world'
return
I did have some success with either using a variable or using the expression format, but these seem like workarounds:

Code: Select all

; With variable
world := "hello%world"

^1::
send, %world%
return

; Expression format
^1::
Send % "hello%world"
return
Is there a better/proper way of doing a literal string?

Thank you.
User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: Sending strings with Numpad events; literals

20 Apr 2021, 18:16

Code: Select all

NumpadEnd::Send {Shift up}hello world
Or:

Code: Select all

NumpadEnd Up::Send hello world
I wouldn't call escaping or quoting strings workarounds. I would call it syntax! :)

More syntax:

Code: Select all

Send,
( %
This%that
)
melds
Posts: 2
Joined: 20 Apr 2021, 17:11

Re: Sending strings with Numpad events; literals

20 Apr 2021, 19:04

mikeyww wrote:
20 Apr 2021, 18:16
I wouldn't call escaping or quoting strings workarounds. I would call it syntax! :)

Haha, fair point. I guess I was saying that I don't know if there's a more-correct way of doing it. It also seemed weird that the shift would matter for one type of key but not for another and didn't know if it was the way I was calling it, expected behavior, or a bug/quirk.
mikeyww wrote:
20 Apr 2021, 18:16

Code: Select all

Send,
( %
This%that
)
That's an interesting format. It seems to be a mix of the legacy and "expression" format. Is that right? Do you need the comma after "send" in this format?

Thank you for your help.
User avatar
mikeyww
Posts: 26939
Joined: 09 Sep 2014, 18:38

Re: Sending strings with Numpad events; literals

20 Apr 2021, 19:15

In my view, there aren't correct or incorrect methods, just methods that work, and ones that do not work.

Numpad can be tricky-- a bit different from other keys. It might be a quirk, not a bug.

Regarding continuation lines, they are neither expressions nor legacy (though can use expressions), but a particular type of syntax used in AHK.

To find out if you need comma: take it out, and then test!

I believe that you do need comma in this case, to signal that a continuation section follows.

Explained: Continuation sections, method #2

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 339 guests