Autohotkey: Conflict between functions using the same key

我是研究僧i 提交于 2019-12-11 02:19:00

问题


I using a lot the "$" lately, and in my (Spanish) keyboard I must press Shift+4 every time, so I decided to use AutoHotkey to make it faster. The idea make it faster by using the "ç" key as I don't use it very often.

ç::
  Send $; new use of the key
Return

This works well but sometimes I do need to write "ç" and "Ç", so I tried to add this

!ç::
   Send ç  ; to get the "ç" back in game
Return

+ç::
   Send Ç ;original use of the "ç" key
Return

But it's not working (keep sending $, as "ç" is now "$"). I feel like this should be pretty obvious, but still can't find a solution. Thanks for your time


回答1:


Preferred intuitive way: Use ç::$ instead of command block.

This will re-map the key instead of assigning it a macro. This way is intuitive in AHK scripting because primary and secondary syntax nicely corresponds with primary and secondary intent, i.e.:

  1. (primary) completely remapping the key (in AHK this is done without macros)
  2. (secondary) adding some macros doing non-standard functionalities

• it does not complicate the thing unnecessarily using #InputLevel prioritization

Your complete code after the change:

!ç::
   Send ç  ; to get the "ç" back in game
Return

+ç::
   Send Ç ;original use of the "ç" key
Return

; new use of the key
; ### this code has to be b̲e̲l̲o̲w̲ the macros
ç::$

Tested, it works as expected. (In version 1.1.25.01, 2017-03-05)




回答2:


The easiest way to solve this would be to increase the #InputLevel For your remapped hotkey.

#InputLevel 1
ç::
  Send $ ; new use of the key
Return
#InputLevel 0

This prevents it from being fired buy the script. A hotkey won't be executed as a result of Send if the InputLevel >= SendLevel. They are both 0 by default.

Actually in this case the problem is not with SendLevel(it is not greater than InputLevel) but with the ç hotkey being registered as a reg hotkey, reg hotkeys can't distinguish between simulated and real input so it will always be fired.

Using #UseHook on instead of setting the input level will also solve the problem. #InputLevel 1 makes ç a k-hook key (because all hotkeys with InputLevel > 0 use the keyboard hook). And in this case this is what's important and not the level itself.



来源:https://stackoverflow.com/questions/45651087/autohotkey-conflict-between-functions-using-the-same-key

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!