[GH-ISSUE #538] Issues trying to use AutoHotKey to trigger Barrier #418

Open
opened 2026-05-05 06:20:43 -06:00 by gitea-mirror · 13 comments
Owner

Originally created by @da3dsoul on GitHub (Jan 5, 2020).
Original GitHub issue: https://github.com/debauchee/barrier/issues/538

Operating Systems

Server: Windows 10 1909

Client: Linux Kernel 5.4 (a fucked up frankenstein that started as a buntu)

Barrier Version

2.3.2

Steps to reproduce bug

So I'm trying to put Barrier in an automated process. I have a Windows desktop and a linux server both connected to single LG TV. I made a script that changes my TV input, and Barrier handles the mouse and keyboard. I am using AutoHotKey, because I can't figure out a better way to do this.

I set the hotkey to switch to the server to a bunch of modifiers + F12, to switch back, the same + F11 in barrier.
In AutoHotKey, I have it listen for a different set of modifiers and the same F keys.
AutoHotKey captures the keys, switches my TV input, and then fires the keys for barrier to switch.

The Issue

When AutoHotKey fires the keys, barrier takes them, moves the focus, then AutoHotKey can't release them properly (I think....). I've tried every which way I can think of to fire the keys with AutoHotKey.

Log: https://gist.github.com/da3dsoul/d76d948ac8638e500691b0d3349d51fc

Other info

  • Does this bug prevent you from using Barrier entirely? No, but it's annoying
Originally created by @da3dsoul on GitHub (Jan 5, 2020). Original GitHub issue: https://github.com/debauchee/barrier/issues/538 ### Operating Systems ### Server: Windows 10 1909 Client: Linux Kernel 5.4 (a fucked up frankenstein that started as a buntu) ### Barrier Version ### 2.3.2 ### Steps to reproduce bug ### So I'm trying to put Barrier in an automated process. I have a Windows desktop and a linux server both connected to single LG TV. I made a script that changes my TV input, and Barrier handles the mouse and keyboard. I am using AutoHotKey, because I can't figure out a better way to do this. I set the hotkey to switch to the server to a bunch of modifiers + F12, to switch back, the same + F11 in barrier. In AutoHotKey, I have it listen for a different set of modifiers and the same F keys. AutoHotKey captures the keys, switches my TV input, and then fires the keys for barrier to switch. #### The Issue #### When AutoHotKey fires the keys, barrier takes them, moves the focus, then AutoHotKey can't release them properly (I think....). I've tried every which way I can think of to fire the keys with AutoHotKey. Log: https://gist.github.com/da3dsoul/d76d948ac8638e500691b0d3349d51fc ### Other info ### * Does this bug prevent you from using Barrier entirely? No, but it's annoying
Author
Owner

@da3dsoul commented on GitHub (Jan 5, 2020):

Okay, I managed to work around this a bit by making AutoHotKey wait until all modifier keys are up to trigger the barrier hotkey, and I set barrier's hotkeys to key that I don't have (F13 and F14) without modifiers. It stopped holding down the modifier keys, but I'm still working on getting it to switch back now, as barrier consumes the keypresses, preventing a switch back. It worked before, as the hotkeys coincidentally overlapped, and that caused both to be triggered at once before. Luckily Ctrl+Alt+Delete works to force focus back to the server (windows).

<!-- gh-comment-id:570856883 --> @da3dsoul commented on GitHub (Jan 5, 2020): Okay, I managed to work around this a bit by making AutoHotKey wait until all modifier keys are up to trigger the barrier hotkey, and I set barrier's hotkeys to key that I don't have (F13 and F14) without modifiers. It stopped holding down the modifier keys, but I'm still working on getting it to switch back now, as barrier consumes the keypresses, preventing a switch back. It worked before, as the hotkeys coincidentally overlapped, and that caused both to be triggered at once before. Luckily Ctrl+Alt+Delete works to force focus back to the server (windows).
Author
Owner

@sorin25 commented on GitHub (Jan 8, 2020):

You might try to switch the roles and use the linux as a server and use the --screen-change-script option to switch the inputs of the TV.
Any luck with authotkey ? (I'm trying to do a similar thing, but I'm forced to use the windows machine as server)

<!-- gh-comment-id:572196557 --> @sorin25 commented on GitHub (Jan 8, 2020): You might try to switch the roles and use the linux as a server and use the --screen-change-script option to switch the inputs of the TV. Any luck with authotkey ? (I'm trying to do a similar thing, but I'm forced to use the windows machine as server)
Author
Owner

@da3dsoul commented on GitHub (Jan 8, 2020):

Kind of. I got a working setup, but sometimes I need to send the commands multiple times, as barrier needs to switch before autohotkey is fired

<!-- gh-comment-id:572201804 --> @da3dsoul commented on GitHub (Jan 8, 2020): Kind of. I got a working setup, but sometimes I need to send the commands multiple times, as barrier needs to switch before autohotkey is fired
Author
Owner

@sorin25 commented on GitHub (Jan 8, 2020):

Can you share your autohotkey script ? I can manage switching the input of the monitor, but can't seem to figure out how to send keys to barrier.

<!-- gh-comment-id:572273091 --> @sorin25 commented on GitHub (Jan 8, 2020): Can you share your autohotkey script ? I can manage switching the input of the monitor, but can't seem to figure out how to send keys to barrier.
Author
Owner

@da3dsoul commented on GitHub (Jan 9, 2020):

Basically, I don't send keys to barrier. I'll up it in a few.

<!-- gh-comment-id:572349009 --> @da3dsoul commented on GitHub (Jan 9, 2020): Basically, I don't send keys to barrier. I'll up it in a few.
Author
Owner

@csm10495 commented on GitHub (May 13, 2020):

Hey @da3dsoul did you ever have issues where AHK macros wouldn't work if in the other computer's screen? I'm having that right now

<!-- gh-comment-id:628196109 --> @csm10495 commented on GitHub (May 13, 2020): Hey @da3dsoul did you ever have issues where AHK macros wouldn't work if in the other computer's screen? I'm having that right now
Author
Owner

@da3dsoul commented on GitHub (May 13, 2020):

Yeah scroll up a bit. Basically, you send the command to switch as part of the command

<!-- gh-comment-id:628223191 --> @da3dsoul commented on GitHub (May 13, 2020): Yeah scroll up a bit. Basically, you send the command to switch as part of the command
Author
Owner

@da3dsoul commented on GitHub (May 13, 2020):

I've been trying to get a better implementation of this, but I got a weird issue where barrier just wouldn't take keyboard input at all. I don't know why

<!-- gh-comment-id:628223546 --> @da3dsoul commented on GitHub (May 13, 2020): I've been trying to get a better implementation of this, but I got a weird issue where barrier just wouldn't take keyboard input at all. I don't know why
Author
Owner

@csm10495 commented on GitHub (May 13, 2020):

I'm not sure that makes sense. If i make a macro that does a msgbox when i hit the 1 key, the msgbox won't come up if my mouse is in on the other barrier system.

<!-- gh-comment-id:628231857 --> @csm10495 commented on GitHub (May 13, 2020): I'm not sure that makes sense. If i make a macro that does a msgbox when i hit the 1 key, the msgbox won't come up if my mouse is in on the other barrier system.
Author
Owner

@da3dsoul commented on GitHub (May 13, 2020):

My specific system is designed to execute a command on switch (such as switching inputs on the TV)

<!-- gh-comment-id:628233857 --> @da3dsoul commented on GitHub (May 13, 2020): My specific system is designed to execute a command on switch (such as switching inputs on the TV)
Author
Owner

@da3dsoul commented on GitHub (May 16, 2020):

Okay, I got something that works with only one keypress.

Barrier

section: screens
	THE-THRONE:
		halfDuplexCapsLock = false
		halfDuplexNumLock = false
		halfDuplexScrollLock = false
		xtestIsXineramaUnaware = false
		preserveFocus = false
		switchCorners = none 
		switchCornerSize = 0
	THE-POWERHOUSE:
		halfDuplexCapsLock = false
		halfDuplexNumLock = false
		halfDuplexScrollLock = false
		xtestIsXineramaUnaware = false
		preserveFocus = false
		switchCorners = none 
		switchCornerSize = 0
end

section: aliases
end

section: links
	THE-THRONE:
	THE-POWERHOUSE:
end

section: options
	relativeMouseMoves = false
	screenSaverSync = false
	win32KeepForeground = false
	clipboardSharing = true
	switchDelay = 250
	switchCorners = none 
	switchCornerSize = 0
	keystroke(Control+Shift+F11) = ;switchToScreen(THE-POWERHOUSE)
	keystroke(Control+Shift+F12) = ;switchToScreen(THE-THRONE)
end

AutoHotkey

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Event  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir C:\Users\da3ds\Documents\GitHub\LGWebOSRemote\LGTV  ; Ensures a consistent starting directory.

F13 Up::
Sleep 100
Run, LGTV TV setInput HDMI_2
sleep 500
Send ^+{F11}
return

F14 Up::
Sleep 100
Run, LGTV TV setInput HDMI_1
sleep 500
Send ^+{F12}
return

You may need to add F13 and F14 (in this example) to the ImmuneKeys.txt, but I didn't need to.

I remapped my Scroll Lock and Pause buttons to F13 and F14.

<!-- gh-comment-id:629570403 --> @da3dsoul commented on GitHub (May 16, 2020): Okay, I got something that works with only one keypress. Barrier ``` section: screens THE-THRONE: halfDuplexCapsLock = false halfDuplexNumLock = false halfDuplexScrollLock = false xtestIsXineramaUnaware = false preserveFocus = false switchCorners = none switchCornerSize = 0 THE-POWERHOUSE: halfDuplexCapsLock = false halfDuplexNumLock = false halfDuplexScrollLock = false xtestIsXineramaUnaware = false preserveFocus = false switchCorners = none switchCornerSize = 0 end section: aliases end section: links THE-THRONE: THE-POWERHOUSE: end section: options relativeMouseMoves = false screenSaverSync = false win32KeepForeground = false clipboardSharing = true switchDelay = 250 switchCorners = none switchCornerSize = 0 keystroke(Control+Shift+F11) = ;switchToScreen(THE-POWERHOUSE) keystroke(Control+Shift+F12) = ;switchToScreen(THE-THRONE) end ``` AutoHotkey ``` #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. ; #Warn ; Enable warnings to assist with detecting common errors. SendMode Event ; Recommended for new scripts due to its superior speed and reliability. SetWorkingDir C:\Users\da3ds\Documents\GitHub\LGWebOSRemote\LGTV ; Ensures a consistent starting directory. F13 Up:: Sleep 100 Run, LGTV TV setInput HDMI_2 sleep 500 Send ^+{F11} return F14 Up:: Sleep 100 Run, LGTV TV setInput HDMI_1 sleep 500 Send ^+{F12} return ``` You may need to add F13 and F14 (in this example) to the ImmuneKeys.txt, but I didn't need to. I remapped my Scroll Lock and Pause buttons to F13 and F14.
Author
Owner

@rodrigo-o commented on GitHub (Jul 3, 2020):

I did something similar to what you use but with no effect. In my case, the keystroke is correctly pressed on the server working as expected but I have the same AHK in the client when going back to the server display input and the keystroke didn't work. Could it be something related to barrier capturing keystrokes only from the server or the physical keyboard, and not simulated ones in the client?

<!-- gh-comment-id:653675517 --> @rodrigo-o commented on GitHub (Jul 3, 2020): I did something similar to what you use but with no effect. In my case, the keystroke is correctly pressed on the server working as expected but I have the same AHK in the client when going back to the server display input and the keystroke didn't work. Could it be something related to barrier capturing keystrokes only from the server or the physical keyboard, and not simulated ones in the client?
Author
Owner

@da3dsoul commented on GitHub (Jul 3, 2020):

In my setup, I did not have AHK on the client (since it's not Windows, mostly)

<!-- gh-comment-id:653696060 --> @da3dsoul commented on GitHub (Jul 3, 2020): In my setup, I did not have AHK on the client (since it's not Windows, mostly)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/barrier#418
No description provided.