AutoHotkey - 我想将A设置为Shift A.

时间:2014-02-10 01:18:15

标签: macros key autohotkey remap

有人可以告诉我如何在AutoHotkey中编辑脚本吗?

我使用宏录制器,执行多次重复性任务,即“向上移动向下移动”多次,所以我用来反复按下宏快捷键。问题是,在我使用的宏录制器中,如果你使用修改器调用shorcut来调用宏(即Shift A),那么每次要执行宏时都必须释放修改器,所以我通常必须(按Shift,按A,释放Shift并释放A),每次我想调用宏,而不是按Shift键,按住它,然后按下并释放A多次。更容易。 我正在寻找一个可以解决这个问题的AutoHotKey脚本,我有很多这样的宏,所以我不能为每个宏创建一个bat或exe文件,我基本上需要一个AutoHotkey 脚本如:

如果是keystate,SHIFT,P 一个:: 发送(下移) 发送(向下) 发送(向上移动) 发送(向上)

或每次按A时可以发送Shift和A键的任何其他脚本,但仅当按下Shift键时才会发送。

我一直在尝试循环,但我只是不知道如何让它停止。提前谢谢。

考虑到每次我想要调用一个宏时,我都不需要释放并再次按下“Shift + a”,而且还需要“Alt + a”,以及“Alt + Win + a”,每个不同的组合调用不同的宏。因此,将“a”键设置为始终为“Shift + a”将是个坏主意,因为我需要“a”键来执行不同的宏,根据这些宏同时按下其他修改键。谢谢高级。

我在这个应用程序中使用的热键列表是(每个人都做了不同的事情,并且它不能被任何其他热键替换)

Alt + A
Shift + A
Win + A
Alt + Shift + A
Win + Alt + A

等大多数字母(S,D,Q,W,E等,以及mubers 1,2,3等) 也:

Shift + Tab
Win + Tab
Alt + Capslock
Win + Alt + Capslock

(释放Shift和Tab真的很烦人,再次按下它们,每次我想运行一个宏,我多次重复运行这个宏) 我认为这些都是热键,他们都做了不同的事情,我每次都重复运行。

请,我确实需要一个脚本,可以根据同时按下其他修改键的相同“a”键启动不同的操作。谢谢高级。我非常感激。

嗨罗伯特,我不太清楚你说的是什么,但我编辑了这样的剧本

#MaxThreadsPerHotkey 2

#SingleInstance Force
#installKeybdHook
#Persistent
AppName=MyKeys
Menu, Tray, Tip, %AppName%
Menu, Tray, Icon , Shell32.dll, 45, 1 ; 45, 28, 113, 74, 134
TrayTip, %AppName%, Started, 1 


*a::
GoSub, MyGetKeyStateSub
If (MyGetKeyStateValue=0)
{
    SendInput, a
}
Else
{
    if( MyGetKeyStateValue & 1 > 0) ; Compare first bit
        send {LAlt down}
        send {d down}
        send {LAlt up}
        send {d up}
    if( MyGetKeyStateValue & 10 > 0) ; compare second bit
        MsgBox, RShift
    if( MyGetKeyStateValue & 100 > 0) ; compare third bit
        send {LAlt down}
            send {d down}
        send {LAlt up}
        send {d up}
    if( MyGetKeyStateValue & 1000 > 0)
        MsgBox, RShift
    if( MyGetKeyStateValue & 10000 > 0)
        MsgBox, LAlt
    if( MyGetKeyStateValue & 100000 > 0)
        MsgBox, RAlt
    if( MyGetKeyStateValue & 1000000 > 0)
        MsgBox, LWin
    if( MyGetKeyStateValue & 10000000 > 0)
        MsgBox, RWin
    if ( MyGetKeyStateValue & 00000011 > 0) ; If LCtrl AND LShift pressed
        MsgBox, LCtrl AND LShift
}
Return


MyGetKeyStateSub:
MyGetKeyStateValue:=0
if getkeystate("LCtrl", P)
    MyGetKeyStateValue+=1 ; set least significant bit
if getkeystate("RCtrl", P)
    MyGetKeyStateValue+=2 ; set 2nd least significant bit, etc, etc.
if getkeystate("LShift", P)
    MyGetKeyStateValue+=4
if getkeystate("RShift", P)
    MyGetKeyStateValue+=8
if getkeystate("Lalt", P)
    MyGetKeyStateValue+=16
if getkeystate("Ralt", P)
    MyGetKeyStateValue+=32
if getkeystate("LWin", P)
    MyGetKeyStateValue+=64
if getkeystate("RWin", P)
    MyGetKeyStateValue+=128
Return



*d::
GoSub, MyGetKeyStateSub
If (MyGetKeyStateValue=0)
{
    SendInput, d
}
Else
{
    if( MyGetKeyStateValue = 1) ; LAlt
    {
        SendInput, {LAlt Down}d{LAlt Up}
        Return
    }
    if( MyGetKeyStateValue = 4) ; LWin
    {
        SendInput, {LAlt Down}{LWin Down}d{LAlt Up}{LWin Up}
        Return
    }
}
Return

然后打开程序,同样的dident工作, 我第一次按Alt D我得到了宏,第二次按D键拿着alt键,我得到一个普通的D.

我在考虑你所说的与XY问题相关的内容,也许我应该将所有宏从HK4(Hot Keyboard Pro 4)重建为AutoHotkey。我在HK4 GUI的帮助下创建了很多宏,但是宏本身存储在xml脚本文件中,我用文本编辑器打开了这个文件一次,它的巨大!我需要花多少时间来编写脚本AHK里面的所有这些宏? 我设置了25个适用于每个宏(如200个宏)的变量,主要是鼠标移动,鼠标点击,从应用程序内的浮动窗口复制所选文本(数值),对它们应用算术运算并将结果粘贴到其中再次使用盒子(HK4有和播放键的选项,因为否则它不能粘贴到应用程序内),运行取决于哪些软件,哪些浮动窗口名称,以及启用或禁用哪些变量(倒置条件),还要切换宏(用一个热键在两个宏之间切换),我的意思是,我需要花多少钱来学习如何在AHK中编写所有这些类型的宏?我在互联网上看了一下,但很难理解每个发布的情况都没有完全适用于我打算做的事,谢谢罗伯特,你建议我做什么?我的意思是,我会在AHK中重建我的所有宏,因为在AHK中我不必释放修改键来同时执行宏多次,那么Autoit更容易学习?我看过它有macrorecorder?感谢。

2 个答案:

答案 0 :(得分:0)

这是怎么回事?

:*:a::+a

如果你想要表达这种想法,你可以将它封装在#IfWinActive语句中,只有当特定应用程序处于活动状态时才能获得转换a,否则所有的a将一直变为Shift A ...

这个怎么样:

:*:a::
    Send, {Shift Down}a{Shift Up} ; or use the more modern SendInput
Return

这是一个如何做到这一点的小例子。不确定这是否符合您的要求。在示例中,我仅为字母a创建了此字符,但您可以通过对其他字母重复此操作来扩展它。

#SingleInstance Force
#installKeybdHook
#Persistent
AppName=MyKeys
Menu, Tray, Tip, %AppName%
Menu, Tray, Icon , Shell32.dll, 45, 1 ; 45, 28, 113, 74, 134
TrayTip, %AppName%, Started, 1 


*a::
GoSub, MyGetKeyStateSub
If (MyGetKeyStateValue=0)
{
    SendInput, a
}
Else
{
    if( MyGetKeyStateValue & 1 > 0) ; Compare first bit
        MsgBox, LCtrl
    if( MyGetKeyStateValue & 10 > 0) ; compare second bit
        MsgBox, RCtrl
    if( MyGetKeyStateValue & 100 > 0) ; compare third bit
        MsgBox, LShift
    if( MyGetKeyStateValue & 1000 > 0)
        MsgBox, RShift
    if( MyGetKeyStateValue & 10000 > 0)
        MsgBox, LAlt
    if( MyGetKeyStateValue & 100000 > 0)
        MsgBox, RAlt
    if( MyGetKeyStateValue & 1000000 > 0)
        MsgBox, LWin
    if( MyGetKeyStateValue & 10000000 > 0)
        MsgBox, RWin
    if ( MyGetKeyStateValue & 00000011 > 0) ; If LCtrl AND LShift pressed
        MsgBox, LCtrl AND LShift
}
Return


MyGetKeyStateSub:
MyGetKeyStateValue:=0
if getkeystate("LCtrl", P)
    MyGetKeyStateValue+=1 ; set least significant bit
if getkeystate("RCtrl", P)
    MyGetKeyStateValue+=2 ; set 2nd least significant bit, etc, etc.
if getkeystate("LShift", P)
    MyGetKeyStateValue+=4
if getkeystate("RShift", P)
    MyGetKeyStateValue+=8
if getkeystate("Lalt", P)
    MyGetKeyStateValue+=16
if getkeystate("Ralt", P)
    MyGetKeyStateValue+=32
if getkeystate("LWin", P)
    MyGetKeyStateValue+=64
if getkeystate("RWin", P)
    MyGetKeyStateValue+=128
Return
爱德华,这是一个在我的情况下似乎工作得很好的例子,可能是你的应用程序正在查看被按下的物理键。在这种情况下,我会去监视您正在控制的窗口的状态,以查看外观是否需要停止或继续。在这个例子中,我将子程序保留了,因为它没有改变(但你需要它在这里)。

*d::
GoSub, MyGetKeyStateSub
If (MyGetKeyStateValue=0)
{
    SendInput, d
}
Else
{
    if( MyGetKeyStateValue = 1) ; LCtrl
    {
        ;MsgBox, LCtrl
        SendInput, {LShift Down}d{LShift Up}
        Return
    }
    if( MyGetKeyStateValue = 4) ; LShift
    {
        ;MsgBox, LShift
        SendInput, {LCtrl Down}{LShift Down}d{LShift Up}{LCtrl Up}
        Return
    }
}
Return

答案 1 :(得分:0)

只需使用a::A,保存并运行即可。 A被解释为Shift + a,并将与密钥重新映射一起使用。这也适用于#IfWinActive#IfWinExist