将 Ctrl 重新映射到 Alt,并保留 Alt+Tab 和 Ctrl+Tab

将 Ctrl 重新映射到 Alt,并保留 Alt+Tab 和 Ctrl+Tab

我正在使用自动热键来交换 Ctrl 和 Alt

LAlt::LCtrl
LCtrl::LAlt 

这很有效,但最重要的是我想将 Alt+Tab 和 Ctrl+Tab 保留在原来的位置。

我已经尝试了很多不同的代码片段,但到目前为止都没有真正发挥作用。

我最接近完全可行的解决方案,但只适用于 Alt+Tab,而没有 Shift+Alt+Tabhttps://stackoverflow.com/questions/18454895/using-auto-hotkey-to-swap-ctrl-alt-and-implement-ctrl-tab

答案1

明白了,现在可以了!

方向是对的,但代码中有几个问题。特别是 LShift 未进行检查是否为假,因此第一个语句始终为真。

我还添加了对 Ctrl+Tab 的支持。

*tab:: 
{   
    if (GetKeyState("LAlt", "P") AND GetKeyState("LShift", "P") = false) {     
        Send {LControl up}{LAlt down}{tab}
        KeyWait, tab  
    } else if (GetKeyState("LAlt", "P") AND GetKeyState("LShift", "P")) {     
        Send {LControl up}{LShift down}{LAlt down}{tab}
        KeyWait, tab
    } else if (GetKeyState("LCtrl", "P") AND GetKeyState("LShift", "P") = false) {     
        Send {LAlt up}{LCtrl down}{tab}
        KeyWait, tab
    } else if (GetKeyState("LCtrl", "P") AND GetKeyState("LShift", "P")) {  
        Send {LAlt up}{LShift down}{LCtrl down}{tab}
        KeyWait, tab
    } else if (GetKeyState("LWin", "P") AND GetKeyState("LShift", "P") = false) {     
        Send {LWin down}{tab}
        KeyWait, tab
    } else if (GetKeyState("LWin", "P") AND GetKeyState("LShift", "P")) {  
        Send {LShift down}{LWin down}{tab}
        KeyWait, tab
    } else {   
        send {tab}
    }      
    return
}

~LAlt Up::
{   
    send {LAlt up}
    return
}

~LCtrl Up::
{   
    send {LCtrl up}
    return
}

LAlt::LCtrl 
LCtrl::LAlt

答案2

由于我仅从您链接的答案中提供的代码示例中进行操作,因此我整理了以下代码。我不知道“Shift+Alt+Tab”会执行什么操作,因为我的系统上没有响应,所以您必须为我进行测试以验证这是否具有所需的效果。

*tab::
{   if (GetKeyState("LAlt", "P"))  
{   Send {LControl up}{Alt down}{tab}
    KeyWait, tab  
}else if (GetKeyState("LAlt", "P")) AND (GetKeyState("LShift", "P"))  
{ Send {LControl up}{LShift down}{Alt down}{tab}
    KeyWait, tab  
}else   
{   send {tab}
}      
return
}          
~LAlt Up::
{   send {lAlt up}
return
}
LAlt::LCtrl 
LCtrl::LAlt  

答案3

对我来说@herkulano 版本在 Windows10 上不可靠。有时它会运行不同的密钥,导致我无法工作。

相反,我使用这个,它也可以与 Emacs 一起使用,以实现类似的组合C-M--

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
; The .ahk text file needed to be saved with UTF8-BOM encoding rather than UTF8
; https://stackoverflow.com/questions/15635635/how-do-i-use-unicode-in-autohotkey
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

global sendLAltUpOnLCtrlUp := 0

;; https://superuser.com/questions/984343/remap-ctrl-to-alt-and-keep-alttab-and-ctrltab/1332713#1332713
;; https://autohotkey.com/board/topic/96465-switch-alt-and-ctrl-retain-alt-tab/
;; Let LCtrl sends LWin, LWin sends LAlt and LAlt sends LCtrl using SharpKeys and then
*tab:: 
{
    if (GetKeyState("LCtrl", "P") AND GetKeyState("LShift", "P") = false) {
        sendLAltUpOnLCtrlUp := 1
        Send {LCtrl up}{LAlt down}{tab}
        KeyWait, tab  
    } else
    if (GetKeyState("LCtrl", "P") AND GetKeyState("LShift", "P")) {
        sendLAltUpOnLCtrlUp := 1
        Send {LCtrl up}{LShift down}{LAlt down}{tab}
        KeyWait, tab
    } 
    else {   
        send {tab}
    }      
    return
}

~LCtrl up::
{   
    if(sendLAltUpOnLCtrlUp == 1) {
      sendLAltUpOnLCtrlUp := 0
      send {LAlt up}
    } else {
      send {LCtrl up}
    }
    return
}

~LAlt up::
{   
    send {LAlt up}
    return
}

;; Example how to insert polish diactrics with `RAlt + Shift + A` etc.
;; https://pl.m.wikipedia.org/wiki/Alfabet_polski
>!+a::Send {U+0104}
>!a::Send {U+0105}

答案4

将其放在单独的.ahk

SendMode Input 
*LAlt::
    send {LCtrl down}
    Keywait, Lalt
    send {LCtrl up}
return
*LCtrl::
    send {Lalt down}
    Keywait, LCtrl
    send {Lalt up}
return

另一件事也是如此.ahk

SendMode Input 

LAlt & Tab::
    send {Lalt down}{Tab}
return 

+esc::Exitapp

然后运行两个脚本(先运行第一个)。

相关内容