I have two hosts (windows-7) running side by side. I use Mouse without Borders to use a single mouse/keyboard (using Synergy I have the same issue, so all here applies too).

In each host I am running some AHK scripts that provide some keyboard shortcuts. So if my setup is like this:

  • Host A - AHK script A - keyboard A
  • Host B - AHK script B - keyboard A (via Mouse without borders/synergy)

While typing in:

  • Host A: my hotkey (for example CapsLock-S is always handled by the AHK-script-A (obviously)
  • Host B: this is the problem...while typing in this host, my CapsLock-S keyword SOMETIMES is handled by AHK-script-B (the desired output) and SOMETIMES by AHK-script-A.

When typing in Host B only AHK B shortcuts should be triggered, and not a AHK A one (in Host A).

This probably depends on the order on which some programs (ahk etc) were run on each host, or on what application did last have focus or something, but I have no idea.

Does anyone have some clue on how to make this work? Or how to find some determinism on why sometimes it works and sometimes it does not?

  • 2
    I'm just speculating here but maybe AutoHotkey isn't the tool for the job? It is listed under 'Conflicting Software' in Synergy's website – Vinayak Nov 16 '15 at 9:29
  • 1
    If I may suggest an alternative software, you could try re-creating your AHK scripts in AutoIt, which does just about everything that AutoHotkey can do. I'm not sure if it'll work though, so maybe create a few basic scripts that test keyboard functionality first? If you'd rather stay with AHK, let me get back to you later after some testing. – Vinayak Nov 16 '15 at 9:38
  • 1
    It seems like a functional problem with MwB or Synergy. Does this mostly happen only immediately after moving the keyboard from A to B? – harrymc Nov 16 '15 at 20:52
  • 1
    @harrymc I could not trace it to anything specific, I move my mouse all the time between hosts... – albert_vad Nov 16 '15 at 21:58
  • 1
    @Vinayak thanks, but my scripts are too complex to port them to autoit (that I think is pretty similar to AHK), as I don't master neither of them. – albert_vad Nov 16 '15 at 21:59

I'm not familiar with the programs you mention although I think I understand the setup. I would probably debug this by seeing if the keystrokes make it to the AHK script or not and which script is intercepting them.

Two easy tools I might start with...

1) Place a tilde in front of the hotkey definition which lets the keystroke pass through. Replace the code with a simple tooltip to show what's executing. See which keystrokes pass through and which ones get blocked. See if adding the tilde on both systems allows the keystrokes through to the system that is not executing otherwise.

2) Open the script windows on A and B and go to the keystroke log for each. Send the keys that don't appear to be working and see if they are making it to the script of interest (presumably they are not).

The indeterminism you mention is interesting. In Remote Desktop and VNC where you have system A possibly intercepting keystrokes you're trying to get to System B, or possibly the other way around, the behavior is pretty deterministic, or can be changed in the software settings as to which keys are allowed to pass through to the remote host and which ones are not.

If you encounter something that doesn't work right but is at least deterministic, then there are other ways to work around that if your two boxes can communicate, or check to see where the mouse position is for example and don't execute if it's at the edge or past the edge on one monitor for example.

  • 1
    thanks, but this does not help a lot. I'll update the question with further info – albert_vad Nov 16 '15 at 9:01
  • 1
    So AutoHotkey might not see that you've changed hosts. Could you think of a way where AutoHotkey sees your mouse movement that changes the host by having it track MouseGetPos using a timer. If that is possible you might be able to reload the script on the correct host as that might "reset" it to a good state OR disable the script in the host you left and activate it in the host you move to. That way only one script can/will be active. – lintalist Nov 26 '15 at 20:21

Perhaps it is possible to use the #If command and make the hotkeys specific for each host assuming there is someway to distinguish each host by using a one of the built-in variables for the OS https://www.autohotkey.com/docs/Variables.htm#os (A_ComputerName or A_UserName)

More about #If here https://autohotkey.com/docs/commands/_If.htm

  • thanks. But not possible, the scripts I run in both hosts actually contain the same hotkeys... – albert_vad Nov 22 '15 at 22:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.