Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Synergy to control a Mac, the remote keyboard is not available as a device and thus Karabiner cannot react to input #2337

Open
Sheffer opened this issue Jul 1, 2020 · 18 comments

Comments

@Sheffer
Copy link

Sheffer commented Jul 1, 2020

Synergy is a software that allows you to use a single mouse/kbd with a number of networked machines.

My setup:
Synergy server on a Windows PC
Synergy client on Mac with Karabiner

Is it possible to somehow add Synergy as a device that Karabiner can react to?

I just started using Karabiner so I (currently) have no idea of the complexity of managing this.

@Sheffer Sheffer changed the title When using Synergy as client no device exists for synergys keyboards on another machine Using Synergy to control a Mac, the remote keyboard is not available as a device and thus Karabiner cannot react to input Jul 1, 2020
@Rajveer86
Copy link

+1, I would love to be able to control my Mac from my main Windows computer using Synergy/Barrier, whilst still being able to use my Karabiner keybindings. Without Karabiner I'm pretty much useless on a Mac.

@stale
Copy link

stale bot commented Oct 22, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Oct 22, 2020
@Mantene
Copy link

Mantene commented Nov 16, 2020

Is this anywhere on the radar going forward?

@stale stale bot removed the stale label Nov 16, 2020
@nexsja
Copy link

nexsja commented Nov 17, 2020

My issue with this is that if I switch to russian layout then some of the letters still stay in English.
So far I haven't figured out why per se, but it would help if Karabiner would idenfify Barrier as an input source, if that's possible.

@dlobue
Copy link

dlobue commented Feb 23, 2021

I'm in the same boat.

@rjorgenson
Copy link

This gets a +1 from me, would love to have this feature.

@subins2000
Copy link

I'm using Barrier between a Linux machine and Mac. It would be great if barrier input is passed on to Karabiner to engage the PC-style shortcuts. Currently the PC style shortcuts work only on the Mac keyboard but not via inputs through Barrier from the host system.

@iaxx
Copy link

iaxx commented Nov 12, 2021

Yeah I'm pretty much in the same boat, I can't really use my Mac without Karabiner but if I'm connected through Synergy Karabiner simply doesn't pick up my 'virtual' keyboard.

@DanielLaberge
Copy link

Did anyone ever find a workaround, or an alternative app to Synergy where this works?

@MuhammedZakir
Copy link

MuhammedZakir commented Aug 1, 2022

It's unlikely for these kinds of app to support this. It's not simple. See if you can capture key events send by those apps using higher-level remapping tools like Hammerspoon, BetterTouchTool, etc. It may work.

@piyushsoni
Copy link

My issue is the opposite of this. I've made the macbook as Synergy server on which Karabiner works fine, but my only problem is that I want Karabiner to just leave me alone (and not convert keys) when they're sent to the Windows machine. Is there any idea how to do that?

@ylluminate
Copy link

This is indeed still something that needs attention. Definitely not a simple solution it seems, but it is necessary to be able to use apps like Synergy, Barrier, and ShareMouse.

@Rajveer86
Copy link

Rajveer86 commented Jan 25, 2023

In the end I decided to make a PR for Barrier (Synergy-fork) that enhances it's hotkey functionality, so that I can use the same keybinds with Barrier as I use on Karabiner and only when the Mac has mouse focus. Posting here in case it helps anybody else.

For those interested, a test build for Windows can be found here and my Barrier config can be found at the bottom of my PR description here.

I now use this to control my Mac computers from Windows, and make my Mac work like Windows (Ctrl+C to copy, Ctrl+Left to skip a word left e.t.c). I still use Karabiner-Elements when working solely on my Mac.

@Rajveer86
Copy link

My issue is the opposite of this. I've made the macbook as Synergy server on which Karabiner works fine, but my only problem is that I want Karabiner to just leave me alone (and not convert keys) when they're sent to the Windows machine. Is there any idea how to do that?

For your issue (controlling Windows from macOS and disabling Karabiner-Elements when on Windows), you can do the following:

  • Set up Karabiner-Elements to have 2 configs - one that has your keybinds and another that is empty
  • Make Synergy/Barrier write to a log file (mine is stored in /Documents/barrier.log)
  • Create a Hammerspoon config that monitors barrier.log and switches the profile in Karabiner-Elements accordingly. My script for this is as follows:
knu = require("knu") -- https://github.com/knu/hs-knu

-- Switch between Karabiner-Elements profiles as Barrier enters a different host
do
  -- Configure Barrier (https://github.com/debauchee/barrier) to output log to ~/Library/Logs/barrier.log
  local logFile = os.getenv("HOME") .. "/Documents/barrier.log"
  local lineNo = 1
  local host = nil
  local defaultProfile = "Internal Macbook and external keyboard"
  local profileForHost = function (host)
    -- Return the name of a profile suitable for host
    if host == "rajveer-work-threadripper" then
      return "None"
    elseif host == "your-linux-host-name" then
      return "Internal Macbook and external keyboard"
    else
      -- This function is not called when switching back to this host,
      -- but it's good to fall back to the default profile. (or in
      -- case you have another Mac host)
      return defaultProfile
    end
  end
  local watcher = hs.pathwatcher.new(
    logFile,
    function (_files, flagTables)
      for _, flagTable in ipairs(flagTables) do
        if flagTable.itemCreated or flagTable.itemRemoved or flagTable.itemRenamed then
          -- itemRenamed occurs when the log file is rotated
          lineNo = 1
          break
        elseif flagTable.itemModified then
          break
        end
      end

      local f = io.popen(knu.utils.shelljoin("tail", "-n+" .. lineNo, logFile))
      local profile = nil
      for line in f:lines() do
        lineNo = lineNo + 1
        local m = line:match("%] INFO: switch from \".*\" to \"(.*)\" at ")
        if m ~= nil then
          host = m
          goto continue
        end
        if line:match("%] INFO: entering screen") ~= nil then
          profile = defaultProfile
		  -- print("Profile is " , profile)
        elseif line:match("%] INFO: leaving screen") ~= nil then
          profile = profileForHost(host)
		  -- print("Host is ", host, "Profile is " , profile)
        end
        ::continue::
      end
      f:close()
      if profile ~= nil then
        knu.keyboard.switchKarabinerProfile(profile)
      end
    end
  )

  knu.runtime.guard(watcher)
  watcher:start()
end

@ylluminate
Copy link

Do we need to inform Synergy and the Input-Leap (previously known as Barrier) project of a need to address this situation?

@AmirAttoun
Copy link

I dedicated most of today to solving this issue, but none of the solutions I tried worked as intended. Eventually, I found a workaround (partly), though it's not ideal.

I created a custom keyboard layout on Windows, following instructions from a Reddit post about building custom Windows keyboard layouts (https://www.reddit.com/r/Karabiner/comments/p41kz5/switched_to_windows_but_i_cant_live_without/)
On my Mac client, I now have a specific key combination that produces the desired character.
I'll avoid using this combination on the Windows server, so it won't really notice its existence there.
This of course only works with key combos that won't interfere whilst using the host. And this won't work for more complex scenarios.

This solution allows me to use the special character I need on my Mac even though it's not a perfect fix.

@nbolton
Copy link

nbolton commented Sep 3, 2024

inform Synergy

Consider us informed! 🙂

Looks like PR debauchee/barrier#1883 is for a dead Synergy fork, but it could be ported quite easily to the free community edition of Synergy 1 (active project). I'm swamped at the moment, but if anyone has a moment to submit a PR I'd gladly review it.

@krismanme
Copy link

krismanme commented Nov 8, 2024

Wanted to update @Rajveer86's answer, which is working awesome BTW, for those of us using Deskflow,
In my example, MacOS is the server and Windows 11 is the client:

  • Start Deskflow on server(MacOS) and client (Windows 11)
  • Download/install Hammerspoon https://github.com/Hammerspoon/hammerspoon/releases/download/1.0.0/Hammerspoon-1.0.0.zip
  • Our Karabiner-elements key-binds/shortcuts etc. will be be stored in our "Default profile"
  • We need to add an additional empty profile, to do this, In Karabiner-elements > Settings... > Profiles > select "Add New Profile" and add an empty profile. Rename the empty profile "None". Select the empty profile to set your keyboard type.
  • On the server (MacOS) go to Deskflow > Preferences... > Advanced > Log > Check "Log to File" > set log path to /users/YOURUSERNAME/deskflow.log > Save, (replace "YOURUSERNAME" with your user name)
  • Run Hammerspoon, and right-click Hammerspoon in the Status menu and select open config
  • Copy and paste the following config, replace "YOURSERVERHOSTNAME" and "YOURCLIENTHOSTNAME" with your respective client and server host name(s) or IP Address(es), you should match this to the Log output of Deskflow
if hs.fs.attributes("Spoons/Knu.spoon") == nil then
  hs.execute("mkdir -p Spoons; curl -L https://github.com/knu/Knu.Spoon/raw/release/Spoons/Knu.spoon.zip | tar xf - -C Spoons/")
end

knu = require("knu") -- https://github.com/knu/hs-knu
-- Switch between Karabiner-Elements profiles as Deskflow enters a different host

do
  -- Configure Deskflow (https://github.com/deskflow/deskflow) to output log to ~/deskflow.log
  local logFile = os.getenv("HOME") .. "/deskflow.log"
  local lineNo = 1
  local host = nil
  local defaultProfile = "Default profile"
  local profileForHost = function (host)
    -- Return the name of a profile suitable for host
    if host == "YOURCLIENTHOSTNAME" then
      return "None"
    elseif host == "YOURSERVERHOSTNAME" then
      return "Default profile"
    else
      -- This function is not called when switching back to this host,
      -- but it's good to fall back to the default profile. (or in
      -- case you have another Mac host)
      return defaultProfile
    end
  end
  local watcher = hs.pathwatcher.new(
    logFile,
    function (_files, flagTables)
      for _, flagTable in ipairs(flagTables) do
        if flagTable.itemCreated or flagTable.itemRemoved or flagTable.itemRenamed then
          -- itemRenamed occurs when the log file is rotated
          lineNo = 1
          break
        elseif flagTable.itemModified then
          break
        end
      end

      local f = io.popen(knu.utils.shelljoin("tail", "-n+" .. lineNo, logFile))
      local profile = nil
      for line in f:lines() do
        lineNo = lineNo + 1
        local m = line:match("%] INFO: switch from \".*\" to \"(.*)\" at ")
        if m ~= nil then
          host = m
          goto continue
        end
        if line:match("%] INFO: entering screen") ~= nil then
          profile = defaultProfile
		  -- print("Profile is " , profile)
        elseif line:match("%] INFO: leaving screen") ~= nil then
          profile = profileForHost(host)
		  -- print("Host is ", host, "Profile is " , profile)
        end
        ::continue::
      end
      f:close()
      if profile ~= nil then
        knu.keyboard.switchKarabinerProfile(profile)
      end
    end
  )
  knu.runtime.guard(watcher)
  watcher:start()
end
  • right-click Hammerspoon in the Status menu and select reload config

Hammerspoon should now switch between Profiles in Karabiner-elements whenever you move the mouse between hosts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests