Swapping unshifted and shifted versions of keys

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
dgdavis
Posts: 4
Joined: 13 Apr 2024, 16:02

Swapping unshifted and shifted versions of keys

Post by dgdavis » 13 Apr 2024, 18:07

I'm new to Autohotkey and have been trying to use it to swap the shifted and unshifted versions of Semicolon/Colon and Grave/Tilde keys for use in typing in Windows 10. I found online the script below:

Code: Select all

$+;:: Send {Shift Up};{Shift Down}
$;:: Send {Shift Down};{Shift Up}
That works fine for the Semicolon/Colon key. However, when I simply replace the Semicolon symbol in that code with the Grave, and compile that:

Code: Select all

$+`:: Send {Shift Up}`{Shift Down}
$`:: Send {Shift Down}`{Shift Up}
the result is to disable the Grave/Tilde key altogether. I've spend hours fiddling with quote, escapes, etc., but the results have been mostly "bad syntax," and none have worked. I'd be grateful to be told what I'm doing wrong, and how to get this simple script working.

--Donald Davis

[Mod edit: Added [code][/code] tags. Please use them yourself when posting code!]
[Mod edit: Moved topic from AHK v2 help since this is v1 code.]

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

Re: Swapping unshifted and shifted versions of keys

Post by mikeyww » 13 Apr 2024, 18:46

Welcome to this AutoHotkey forum!

Perhaps:

Code: Select all

#Requires AutoHotkey v1.1.33.11
$~::Send ``
$`::Send ~
Explained: Escape sequences

If you are new to AHK, I recommend using its current version, which is v2, instead of this older deprecated version that is no longer developed.

dgdavis
Posts: 4
Joined: 13 Apr 2024, 16:02

Re: Swapping unshifted and shifted versions of keys

Post by dgdavis » 14 Apr 2024, 23:17

Thank you for responding. I'm actually using Autohotkey 1.1.35.0. The code I posted was from a browser search and its AHK version wasn't listed.

The code you suggested:

Code: Select all

$~::Send ``
$`::Send ~
had no apparent effect after compiling--the Grave and Tilde shift state output remained the default.

--dgdavis

[Mod edit: Added [code][/code] tags. Please use them yourself when posting code!]

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

Re: Swapping unshifted and shifted versions of keys

Post by mikeyww » 15 Apr 2024, 05:21

Below is a different test.
  1. Close all other scripts.
  2. Use only this script.
  3. Do not change the script.
  4. Do not add anything to the script.
  5. Ensure that the script is running. A green AutoHotkey icon will be present in the tray.
  6. If you have no luck, change the Send commands to MsgBox, and retest.
  7. Compiling a script that does not work gets you a compiled program that does not work. Fix the script before you compile it.
  8. Test the script in Notepad.

Code: Select all

#Requires AutoHotkey v1.1.33.11
$sc029:: Send {Text}~
$+sc029::Send {Text}``

Code: Select all

; A MsgBox test (US keyboard)
#Requires AutoHotkey v1.1.33.11
$`:: MsgBox Unshifted
$+`::MsgBox Shifted

dgdavis
Posts: 4
Joined: 13 Apr 2024, 16:02

Re: Swapping unshifted and shifted versions of keys

Post by dgdavis » 15 Apr 2024, 14:32

Yes! your first code block does swap the Grave/Tilde shift-state typing output as I want. The second code block creates no text character, but a message window which displays the strings "shifted" or "unshifted" according to the corresponding state of the shift key.

My apology for my confusion about compilation. I was wrongly thinking that the script had to be compiled in order to be executed. What I intended to be doing was to right-click on the .AHK file icon and "Run as Administrator" when doing the testing. Now that the script works, I presume that how to make this the default state in my keyboard is now to compile it to the .EXE version and make it a Windows Startup item.

--dgdavis

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

Re: Swapping unshifted and shifted versions of keys

Post by mikeyww » 15 Apr 2024, 15:40

Good to hear that you have something working.

There is no problem with what you described, but compiling is optional. You can run your complete script without ever compiling it. AutoHotkey.exe (or one of its variants) runs when you execute a script. That takes care of the execution of your code. You can also use that approach for startup if you wish.

How do I put my hotkeys and hotstrings into effect automatically every time I start my PC?

If running the script as administrator is the only way for your script to work, then I guess you need to go with it. If it works without running as admin, then that is what I would recommend. UI Access can work for some UAC issues and is preferred to admin mode.

How do I work around problems caused by User Account Control (UAC)?

dgdavis
Posts: 4
Joined: 13 Apr 2024, 16:02

Re: Swapping unshifted and shifted versions of keys

Post by dgdavis » 15 Apr 2024, 17:42

I like using the tiny .EXE version because once the script is perfected, its disconnection from direct dependence on AutoHotKey proper makes it portable. From my primary Windows 10 computer, I just transferred a copy to a different laptop running Windows 7, where it remaps the key without AutoHotKey even having to be installed. This versatile simplicity is a big advantage. It's surprising how hard I had to search the internet to find this way to do simple reversal of the default shift state for individual key output. Even the Windows PowerToys key remapping could only switch entire keys via Scancode resetting, but not remap which of the two options on one key required pressing Shift. That's a useful ability to have when the default options don't match the keys you type most often. Thanks for your effective aid.

--dgdavis

Post Reply

Return to “Ask for Help (v1)”