Remapping ctrl+win - autohotkey

The first script works, but the second that should remap ctrl+win does not. Why is that?
ctrl::Send {ALT down}{SHIFT down}{SHIFT up}{ALT up}
^lwin::Send {ALT down}{SHIFT down}{SHIFT up}{ALT up}

This works fine for me:
Ctrl & LWin:: msgbox hi
I think the keys Alt and Shift are triggering while you still have not released the keys Ctrl and Win, therefore it’s working all the keys at the same time: Alt, Shift, Ctrl, Win.
Because you just should check if the keys are not pressed at that time.
To do this, we’ll use the function GetKeyState().
Ctrl & LWin Up::
while(!GetKeyState("Ctrl", "P"))
continue
send {ALT down}{SHIFT down}
sleep 40
send {SHIFT up}{ALT up}
; or use “Send {ALT down}{SHIFT down}{SHIFT up}{ALT up}”
; if it works for you
return

Because they are both modifier keys.
Try this instead:
Ctrl & LWin::
Edit:
Then, try using SetKeyDelay and possibly SendEvent, too.
Wait, I found this working just now:
Ctrl & LWin::Send {ALT down}{SHIFT down}
Ctrl & LWin Up::Send {SHIFT up}{ALT up}
Of course, being modifier keys, they need special treatment.
Edit 2:
My shift+alt combination is for changing the keyboard language
Why didn't you say so earlier? : ) I thought you were just replacing modifier combinations.
It's much simpler, then.
This should work:
/*
cf. https://www.autohotkey.com/docs/commands/PostMessage.htm
cf. https://msdn.microsoft.com/en-us/library/windows/desktop/ms632630(v=vs.85).aspx
0x50: WM_INPUTLANGCHANGEREQUEST
0x02: INPUTLANGCHANGE_FORWARD
*/
Ctrl & LWin::PostMessage, 0x50, 2,,, A
Alternatively:
Ctrl & LWin::
KeyWait Ctrl
KeyWait LWin
PostMessage, 0x50, 2,,, A
Return
The above two pieces of code have pros and cons. Experiment and choose what suits your needs.

Related

Apply hotkeys only while AltTab-ing in AutoHotkey

I want to swap AltTab hotkey in Windows 11 for the hotkey Win+Tab. Additionally, I want to map Win+[Arrows] to work for navigating between the windows in the Task Switcher.
This is achieved with the snippet below:
LWin & Tab:: AltTab
LWin & Right:: AltTab
LWin & Left:: ShiftAltTab
However, this triggers the Alt Tab functionality even when trying to organize windows. For example, when typing Win+Left I'd want to send the active window to the left side of the screen.
So the question is: How do I preserve the Win+[Arrow] functionality when I am not alt-tabbing?
Try this
; LWin + Tab = AltTab
<#Tab::
Send, {Alt Down}{Tab}
KeyWait, LWin ; waits for LWin to be relesead
Send, {Alt Up}
return
; LWin + LShift + Tab = ShiftAltTab
<#<+Tab::
Send, {Alt Down}{Shift Down}{Tab}
KeyWait, LWin
KeyWait, LShift
Send, {Alt Up}
return
#IfWinActive Task Switching
*Right:: Send {Right}
*Left:: Send {Left}
#IfWinActive
Wildcard (*): Fires the hotkey even if extra modifiers are being held down
With #user3419279's suggestion I got to this final solution:
LWin & Tab:: AltTab
#IfWinActive Task Switching
*Right:: AltTab
*Left:: ShiftAltTab
*Up::^Up
*Down::^Down
#IfWinActive
This allows me to move vertically and horizontally alongside many windows

Invalid hotkey: Ctrl & CapsLock & L

To map CapsLock to Esc if pressed alone, and use it as a modifier key otherwise, I use this script:
#InstallKeybdHook
SetCapsLockState AlwaysOff
CapsLock::Send {esc}
CapsLock & h::Left
CapsLock & j::Down
CapsLock & k::Up
CapsLock & l::Right
return
To move around virtual desktops in Windows, I wanted to now map Ctrl & CapsLock & l::^#Right. Unfortunately this is not possible and gives an error: Invalid hotkey. Does anybody know why?
Instead of remapping I'd use the Send command to define new hotkeys.
A remapping is not a hotkey. A remapping is two hotkeys (key-down and key-up) with each having the wildcard modifier, as shown in the documentation.
Combinations of three or more keys (Ctrl & CapsLock & l) are not supported.
Or try it this way:
#InstallKeybdHook
SetCapsLockState AlwaysOff
CapsLock::Send {esc}
CapsLock & h::Send {Left}
CapsLock & j::Send {Down}
CapsLock & k::Send {Up}
CapsLock & l::
If GetKeyState("Ctrl", "P")
SendEvent {LWin down}{LCtrl down}{Right down}{LWin up}{LCtrl up}{Right up} ; switch to next virtual desktop
else
Send {Right}
return

Autohotkey remapping Alt Gr to Win Modifyer

I am trying to build a very simple AutoHotkey script but it doesnt seem to be working. I've bought a keyboard with no Win key and no programable hardware layer so I am planning on using AHK to remap the Alt Gr key to the Windows key.
Can anypoint give me pointers to where I am going wrong.
<^>!l::
MsgBox Win L pressed.
return
<^>!r::
Send {# down}
Send {r down}
Send {# up}
Send {# up}
return
<^>!e::
SendInput #&e
return
Using your middle example, it'd be like so:
<^>!r::
SendInput, {LWin Down}r{LWin Up}
Return
You can use RWin or LWin per your preference since it really shouldn't matter at the software level.

Bind one key to three modifier keys autohotkey

i wannna be able to press Alt+Middle Button for simulating Shift+Ctrl+Right Button with AutoHotkey. I did it for simulating two keys. And it worked but it is not working for three keys.
so i wrote that:
LAlt & MButton::Send {Ctrl Down}{Shift Down}{RButton Down}
keywait, LAlt
keywait, MButton
LAlt & MButton Up::Send {Ctrl Up}{Shift Up}{RButton Up}
return
where is the problem?
First thing is that the two keywait lines are never executed as you have your send action on the some line as the hotkey, this will make a one-line hotkey or remap
If you wish to execute multiple lines of code in one hotkey routine you will need to start the routine on the line below the hotkey definition label.
Also try taking a simpler approach be using Autohotkeys remapping capabilities
Can't say this will work for you but give it a shot
!MButton::^+RButton
Hope it helps

Inactivate right click when using it as shortkey

I have successfully made it so that when I hold down the right mouse button I can control the system volume with The scroll wheel. But my problem now is that every time that I release the right button it still right clicks even if I have changed the volume.
I want to retain the normal right click, but not when I have used the right mouse button in a macro (then it should ignore the release of the right mouse button). How do I best add a script to ignore mouse clicks in this situation?
This is what I use at the moment:
~RButton & WheelUp::Send {Volume_Up}
And I like it for its brevity (also, other ways have shown to be buggy), so I hope that there is a simple solution that I have missed.
I think it should be possible to have a timer based solution that works (like for double right click as shortkeys), but I have been unable to use that solution.
Here are solutions I have found that Don't quite solve it:
RButton & WheelUp::Send {Volume_Up} ; inactivates right click
RButton:: click right ; gets right click back, but unable to have right click pressed
;(dragging things with right click, etc would be impossible)
RButton & WheelUp:: Send {Volume_Up}
RButton & WheelDown::Send {Volume_Down}
OK, here is a better solution, I think.
~RButton & WheelUp::
Send {Volume_Up}
SetTimer, CloseContextMenu, 50
return
~RButton & WheelDown::
Send {Volume_Down}
SetTimer, CloseContextMenu, 50
return
CloseContextMenu:
KeyWait, RButton, R
WinGetTitle, active_title, A
WinGetClass, active_class, A
WinActivate, ahk_class Progman ;desktop
WinWaitActive, ahk_class Progman
Send, {ALT Down}{ALT Up} ; try also: Send, {Esc} (remove the Alt command)
SetTimer, CloseContextMenu, off
WinActivate, %active_title% ahk_class %active_class%
return
~RButton & WheelUp::
Send {Volume_Up}
SetTimer, CloseContextMenu, 50
return
~RButton & WheelDown::
Send {Volume_Down}
SetTimer, CloseContextMenu, 50
return
CloseContextMenu:
KeyWait, RButton, R
Send, {Esc}
SetTimer, CloseContextMenu, off
return
Try also this:
#NoEnv
SendMode Input
#SingleInstance Force
Process, Priority, ,High
#InstallKeybdHook
#InstallMouseHook
#UseHook
#MenuMaskKey vk07 ; is used to mask Win or Alt keyup events
; http://ahkscript.org/docs/commands/_MenuMaskKey.htm
return
~RButton & WheelUp::
Send {Volume_Up}
SetTimer, CloseContextMenu, 50
return
~RButton & WheelDown::
Send {Volume_Down}
SetTimer, CloseContextMenu, 50
return
CloseContextMenu:
KeyWait, RButton, R
Send, {ALT Down}{ALT Up}
SetTimer, CloseContextMenu, off
return