作为新的修改器键



我希望;成为一个新的修饰符键以下几乎完美。

`;::
if GetKeyState("LShift", "P")
Send `:
else
Send `;
return
`; & x::
if GetKeyState("LShift", "P")
...
else
...
return

只有第2点。以下愿望列表中的一个不起作用。有人知道如何修复这个代码吗?

  1. ;单独按下时为;
  2. 单独按下时shift ;变为:
  3. ;x作为第二...
  4. shift;x成为第一个...

在我看来,有两种可能的方法可以使第2点发挥作用。

方法1:保持左移键的默认行为

移位+导致按下冒号键。您可以通过在`之前添加波浪号"~"键来获得第2点并删除

else 
send `;

使用~可以保持键的默认行为。新的脚本看起来像这个

~`;::
if GetKeyState("LShift", "P") 
Send `:
return 
`; & x::
if GetKeyState("LShift", "P")
...
else
...
return

通过使用此方法,脚本将能够使用shift+发送

方法2:删除左键的默认行为

在代码中添加以下代码段

LShift::
Send, {} 
return 

这个片段将使第2点起作用,但将使左移键对其他一切都毫无用处。

编辑

方法3:使;等待x

在脚本中添加KeyWait将使其在执行代码之前等待一定的时间。其次,使用Lshift+;作为单独的热键组合将输出到:,从而消除了使用~作为回报的需要。

`;::
KeyWait, `;, T0.2
Send `;
return
LShift & `;::
Send `:
return 
`; & x::
KeyWait, `;, T0.2 
if GetKeyState("LShift", "P")
...
else
...
return 

下面的代码工作得很好,但由于代码重复,代码很难看。也许更干净的代码是可能的。

started := 0
LShift & `;::
if started = 0
started := A_TickCount
return
`;::
if started = 0
started := A_TickCount
return
LShift & `; Up::
if A_TickCount - started < 500
Send `:
started = 0
return
`; Up::
if A_TickCount - started < 500
Send `;
started = 0
return
`; & x::
started = 0 ; <==== !
if GetKeyState("LShift", "P")
...
else
...
return

现在,无论何时与x组合使用(无延迟(或按下超过半秒,键;都可以用作修改键。延迟不是必要的,可以消除;它只是为了防止将意外的修改器按键误解为CCD_ 22。冒号:也能正常工作。

#MaxThreadsPerHotkey 2 ; allow 2 "instances" of the hotkey subroutine to exist simultaneously
`;::
If (A_PriorKey = "`;") ; ; was pressed alone
Send `;
return
LShift & `;:: Send :
`; & x::
if GetKeyState("LShift", "P") ;  ; & LShift & x
Send a
else                          ; ; & x
Send b
return

最新更新