Autohotkey pasting "@" instead of "2" sometimes

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Kaeshya
Posts: 2
Joined: 24 Jun 2022, 11:12

Autohotkey pasting "@" instead of "2" sometimes

Post by Kaeshya » 24 Jun 2022, 11:19

Hi guys,

I'm using the below script to copy and paste "0x26EfB2b024b0C80171a797dB470158F93affd72z". However, the script pastes "0x26EfB2b0@4b0C80171a797dB470158F93affd72z" sometimes. Most of the time, it gets it right. I'm puzzled by what I could be doing wrong since it looks like a simple script. Appreciate any help to fix this. If possible, I would like to avoid copying the text to clipboard first before pasting it since it overwrites my clipboard.

Code: Select all

Numpad5::
Send 0x26EfB2b024b0C80171a797dB470158F93affd72z
return

gregster
Posts: 8992
Joined: 30 Sep 2013, 06:48

Re: Autohotkey pasting "@" instead of "2" sometimes

Post by gregster » 24 Jun 2022, 11:22

Can happen in some target applications. Try text mode (AHK v1.1.27+, in older versions try SendRaw):

Code: Select all

Send {text}0x26EfB2b024b0C80171a797dB470158F93affd72z
(other send modes or key delays might also help, but usually text mode helps already)

lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Autohotkey pasting "@" instead of "2" sometimes

Post by lexikos » 24 Jun 2022, 21:37

Also verify that you are:
  • not running any other scripts (as separate processes) which install a keyboard hook.
  • not running any other programs which install a keyboard hook.
  • using SendMode Input prior to Send, or SendInput instead of Send.
Otherwise, sent keyboard events will generally be interspersed with your own keyboard input.

When you mix in capital letters (you have a few), it will send Shift down or up whenever it needs to change case. Sometimes applications ignore the sequence of keyboard events and instead check the current Shift state, so you get the wrong character if the events are sent faster than the application is processing them (although this doesn't explain how a 2 surrounded by digits and lowercase letters would be transformed to @). {Text} mode avoids this issue because it sends character codes, not key-down and key-up messages.

SendRaw would not make any difference for what you are sending. The only difference between Send and SendRaw is that the characters ^+!#{} have special meaning to Send but not SendRaw.

I'm using the below script to copy and paste ... the script pastes
You aren't, and it doesn't. What you are doing now is effectively telling AutoHotkey to type a long string of characters. Send xyz will send key-down and key-up messages for x, y and z.

Imagine that AutoHotkey is sitting next to you, and you ask her to type this code for you. If you are using the default SendMode, maybe you will jump in and press keys while she's still typing the code. If you are using SendMode Input under the right conditions, it will be like you each have your own keyboard, and any input from yours is buffered (stored for later processing) until she finishes typing.
If possible, I would like to avoid copying the text to clipboard first before pasting it since it overwrites my clipboard.
For long strings, it is pretty much always more reliable to actually copy and paste. Ctrl+V generally requires only 4 key-down/up messages, whereas typing 42 characters requires at least 84 key-down/up messages. More events means it takes longer. The longer it takes, the higher the risk of interference or timing issues.

Typically when using the clipboard to paste text, one would save the old content with something like ClipSaved := ClipboardAll and restore it (after a delay) with Clipboard := ClipSaved. A delay is necessary because it takes time for the program to process the Ctrl+V keystroke and pull the text from the clipboard.

Post Reply

Return to “Ask for Help (v1)”