Simple script to swap left control and windows keys

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
kboom
Posts: 5
Joined: 01 Mar 2022, 14:17

Simple script to swap left control and windows keys

Post by kboom » 27 Apr 2024, 13:46

Hi,
I'm using mac layout keyboard. I really hate using my pinky finger for control so I prefer using my thumb.
I'd like to simply switch both keys.
Right now I have this script which mosty works. Mostly.

Code: Select all

;OPTIMIZATIONS START
#NoEnv
#MaxHotkeysPerInterval 99000000
#HotkeyInterval 99000000
#KeyHistory 0
ListLines Off
Process, Priority, , A
SetBatchLines, -1
SetKeyDelay, -1, -1
SetMouseDelay, -1
SetDefaultMouseSpeed, 0
SetWinDelay, -1
SetControlDelay, -1
SendMode Input
DllCall("ntdll\ZwSetTimerResolution","Int",5000,"Int",1,"Int*",MyCurrentTimerResolution) ;setting the Windows Timer Resolution to 0.5ms, THIS IS A GLOBAL CHANGE
;OPTIMIZATIONS END

if not A_IsAdmin
{
   Run *RunAs "%A_ScriptFullPath%"  ; Requires v1.0.92.01+
   ExitApp
}

LWin::LCtrl
LCtrl::LWin
RWin::RAlt

!`::
WinGet, ActiveProcessName, ProcessName, A
WinGet, WinClassCount, List, ahk_exe %ActiveProcessName%

if (WinClassCount = 1)
    return

if (NextWindow = "")
    NextWindow := 2

element := % WinClassCount%NextWindow%

WinSet, Top,, ahk_id %element%
WinActivate, ahk_id %element%

NextWindow += 1

if (NextWindow > WinClassCount || !getKeyState("Alt"))
    NextWindow := 2

return

; Google Search select text - Ctrl + Shift + G
 ^+g::
 {
  Send, ^c
  Sleep 50
  Run, http://www.google.com/search?q=%clipboard%
  Return
 }
return

; ADO Search select text - Ctrl + Shift + A
 ^+a::
 {
  Send, ^c
  Sleep 50
  Run, https://dev.azure.com/mseng/AzureDevOps/_search?text=%clipboard%
  Return
 }
return
However, it is quite usual that it "gets stuck" so that windows key appears to be "sticky pressed" (sticky feature is OFF in my windows); when I press numbers on my keyboard like 1 it would bring up corresponding tools.
To make it unstuck I need to randomly hit windows and control... not exactly sure how it gets stuck on unstuck.
This is super annoying. Could someone please help me with the right script?

Posting in the v2 section since maybe the v2 script would work better?


I am using windows 11.


[Mod action: Moved topic from “Scripts and Functions (v2)” since that is for sharing working scripts with others, not for asking for help with your scripts.]
User avatar
mikeyww
Posts: 28872
Joined: 09 Sep 2014, 18:38

Re: Simple script to swap left control and windows keys

Post by mikeyww » 27 Apr 2024, 16:03

My approach would be to start with a short, simple script such as the following. See if it works. If it does work, add one more hotkey, and re-test. Test iteratively. Check :arrow: KeyHistory if stuck. Close other scripts and keyboard utilities first.

Code: Select all

#Requires AutoHotkey v1.1.33.11

LWin::LCtrl
LCtrl::LWin
If your script has a bug, then it means that translating it to v2 will yield a new script with a bug.

Testing these remaps does not require any of the other stuff at the top of your script, and does not require running the script as admin. If you do not need a command, then do not use it. You might discover that extraneous commands worsen your script's performance or reliability.

If this script does not work, then you now have a total of two lines to troubleshoot.
Post Reply

Return to “Ask for Help (v2)”