pqrs-org / Karabiner-Elements

Karabiner-Elements is a powerful utility for keyboard customization on macOS Sierra (10.12) or later.
https://pqrs.org/osx/karabiner/
The Unlicense
18.88k stars 838 forks source link

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 4 years ago

Sheffer commented 4 years ago

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.

Rajveer86 commented 4 years ago

+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[bot] commented 4 years ago

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.

Mantene commented 4 years ago

Is this anywhere on the radar going forward?

nexsja commented 4 years ago

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 commented 3 years ago

I'm in the same boat.

rjorgenson commented 3 years ago

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

subins2000 commented 3 years ago

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 commented 3 years ago

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 commented 2 years ago

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

MuhammedZakir commented 2 years ago

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 commented 2 years ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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:

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 commented 1 year ago

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

AmirAttoun commented 3 months ago

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 commented 2 months ago

inform Synergy

Consider us informed! :slightly_smiling_face:

Looks like PR https://github.com/debauchee/barrier/pull/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 commented 1 week ago

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:

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

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