Automatic keyboard/input source switching for OSX

Related tags

Keyboard autokbisw
Overview

Autokbisw - Automatic keyboard input source switcher

Motivation

This small utility was born out of frustation after a mob programming sesssion. The session took place on a french mac book pro, using a pair of french pc keyboards. Some programmers were used to eclipse, others to intellij on linux, others to intellij on mac.

While macOS automatically switches the layout when a keyboard is activated it doesn't change the keymap, meaning we had to remember changing both the OS and the IDE keymap each time we switched developer.

This software removes one of the switches: it memorizes the last active macOS input source for a given keyboard and restores it automatically when that keyboard becomes the active keyboard.

Homebrew

Install as a service using Homebrew:

brew install ohueter/tap/autokbisw
brew services start ohueter/tap/autokbisw

autokbisw needs privileges to monitor all keyboard input. You have to grant these privileges on the first start of the service.

Throubleshooting

If autokbisw doesn't work after the first start of the service, try to restart it:

brew services restart ohueter/tap/autokbisw

If autokbisw still doesn't work even after rebooting, try re-adding the executable manually to System Preferences > Security & Privacy > Privacy > Input Monitoring (after removing existing entries). The path to add should be /usr/local/bin/autokbisw (Intel Macs) or /opt/homebrew/opt/autokbisw/bin/autokbisw (Apple M1 Macs).

Building from source

Clone this repository, make sure you have XCode installed and run the following commands:

cd autokbisw
swift build --configuration release

In the output will be the path to the built program, something like .build/release/autokbisw.

You can run it from the release directory as is.

Installation

To install it in /usr/local/bin, run:

sudo cp .build/release/autokbisw /usr/local/bin/

If you want the program to start automatically when you log in, you can copy the provided plist file to ~/Library/LaunchAgents and load it manually for the first run:

cp eu.byjean.autokbisw.plist ~/Library/LaunchAgents/
launchctl load ~/Library/LaunchAgents/eu.byjean.autokbisw.plist

Troubleshooting

If launchctl returns an error, you may try one of the following:

1. Reboot

Running launchctl sometimes produced inexplainable error messages (to me), that often were gone after rebooting. 🤷‍♂️

2. Unload and load the service again:

launchctl unload ~/Library/LaunchAgents/eu.byjean.autokbisw.plist
launchctl load ~/Library/LaunchAgents/eu.byjean.autokbisw.plist

3. Force a restart of the service:

launchctl kickstart -kp gui/501/eu.byjean.autokbisw

This may be needed on the first run, after permissions to capture all keyboard events have been granted.

501 may need to be replaced with your user id (uid). To find your user id, run:

id

4. Maybe you need to (re-)enable the service:

launchctl enable gui/501/eu.byjean.autokbisw

Acknowledgements

This program has originally been developed by Jean Helou (@jeantil).

Comments
  • Build fails on M1 Macbook Pro

    Build fails on M1 Macbook Pro

    Hi there,

    I've cloned the repo and tried to build it using swift build --configuration release, however, after it complained about not finding a prebuilt standard library for arm64, it errored out with package.swift:4:8: error: no such module 'PackageDescription' import PackageDescription is a recurring error I have seen with other previously downloaded XCode projects. This might be entirely on me, however, I do not know enough about Swift development to be able to come up with a solution to the issue.

    opened by Rithari 11
  • Add an example scenario in the Readme

    Add an example scenario in the Readme

    Hi, not so much an issue, but a way to figure out if I'm doing something wrong

    I installed autokbisw and I see no difference with vanilla. I'm not sure if it isn't working properly or if I am doing something wrong. There are no information in the readme about what is supposed to happen and when.

    I imagine it's supposed to do something like that:

    • start typing with a keyboard 1 to make it active
    • select input source 1 for that keyboard
    • start typing with keyboard 2
    • select input source 2 for that keyboard

    Now, when you type with keyboard 1, input source 1 is used (you can see it change on the upper right) and when using keyboard 2, input source 2 is used.

    That's what I imagine is supposed to happen (but nothing happens here for me), but I can't be sure without a description.

    opened by rdelassus 8
  • [Request] Edit modifier keys too

    [Request] Edit modifier keys too

    Hello, this isn't an issue but a function request. Would it be possible to switch modifier keys (e.g: Ctrl is mapped to CMD, CMD is mapped to Ctrl) when switching keyboard layout ? This way the internal keyboard would have the original settings but any external Windows keyboard would have Windows modifier keys working on iOS. Thanks !

    opened by ItsPops 2
  • Provide binaries via Homebrew (Bottle)

    Provide binaries via Homebrew (Bottle)

    Is it relaly required to have XCode installed or is that an error in the brew installer?

    ❯ brew install ohueter/tap/autokbisw
    
    ....
    
    autokbisw: A full installation of Xcode.app is required to compile
    this software. Installing just the Command Line Tools is not sufficient.
    
    Xcode can be installed from the App Store.
    Error: autokbisw: An unsatisfied requirement failed this build.
    

    Is this an install dependency or does this need to be present when using it? Either way, that's quite a heavy dependency. I'm downloading 13GB now just to switch the language of my KB 😹

    enhancement 
    opened by udondan 2
  • Per-keyboard layout being overriden when starting a Parallels Desktop virtual machine

    Per-keyboard layout being overriden when starting a Parallels Desktop virtual machine

    Hello, I'm using 2 keyboards: a Logitech PC keyboard and the internal Macbook keyboard. The PC keyboard is using a custom layout made with Ukulele and the Macbook keyboard is using the Apple French AZERTY layout. When starting a virtual machine on Parallels Desktop, the layout is switching back to the internal Apple layout and pressing a key on the PC keyboard doesn't make it switch back to the custom layout. I think that this is because of the way Parallels is switching layout, making Autokbisw thinking that the change is user made.

    I will open a ticket to Parallels Desktop, but do you have any clue how to fix that ?

    Thanks

    opened by ItsPops 1
  • install error

    install error

    Hello: When running brew install, it fails with:

    ==> swift build -c release --disable-sandbox
    Last 15 lines from /Users/harv/Library/Logs/Homebrew/autokbisw/01.swift:
    2022-08-29 23:47:01 +0000
    
    swift
    build
    -c
    release
    --disable-sandbox
    
    warning: Failed creating default security location, Error Domain=NSCocoaErrorDomain Code=513 "You don’t have permission to save the file “security” in the folder “org.swift.swiftpm”." UserInfo={NSFilePath=/Users/harv/Library/org.swift.swiftpm/security, NSUnderlyingError=0x6000023ca310 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}
    warning: Failed creating default configuration location, other(1)
    warning: Failed creating default cache location, other(1)
    error: terminated(72): /usr/bin/xcrun --sdk macosx --find xctest output:
        xcrun: error: unable to find utility "xctest", not a developer tool or in PATH
    
    opened by harvbh 1
  • XCode required

    XCode required

    Is it relaly required to have XCode installed or is that an error in the brew installer?

    Is this an install dependency or does this need to be present when using it? Either way, that's quite a heavy dependency. I'm downloading 13GB now just to siwtch the language of my KB 😹

    opened by udondan 1
  • Added a check to prevent switching if the device is a mouse

    Added a check to prevent switching if the device is a mouse

    Thanks for updating this useful tool to work on the latest OSX! My new Logitech mouse reports as a keyboard so it would cause unintended language switching whenever I moved it (same problem as this issue https://github.com/jeantil/autokbisw/issues/18 in the older version). This check to see if it conforms to mouse solves the issue with my setup at least.

    opened by ryanmccardle 0
  • Keyboard

    Keyboard "MX Keys" is recognized as mouse

    I have two Logitech devices - a MX Master 3 (Mouse) and a MX Keys (Keyboard). For mouse events, I see the appropriate message of ignoring events from it when looking at the logs with autokbisw -v 2:

    received event from keyboard MX Master 3-[1133-45091-Logitech-8650418194568778] - 661132639 - 4299630569
    ignoring event as device is a mouse
    

    But this also appears when I am typing in my MX Keys:

    received event from keyboard MX Keys-[1133-45915-Logitech-58FD86B9CF3FE9CA] - 3158248515 - 4299633249
    ignoring event as device is a mouse
    

    Because of this, I currently can't use autokbisw to switch language inputs, because the external keyboard is not recognized and so will not trigger a language change.

    Both devices are connected through Bluetooth on macOS Monterey 12.6.1

    help wanted 
    opened by renekann 1
  • Fix Keychron keyboard being detected as a mouse

    Fix Keychron keyboard being detected as a mouse

    Currently, my Keychron keyboard is being detected as a mouse by autokbisw.

    To fix this problem, I patched IOKeyEventMonitor.swift so that conformsToMouse is false for Keychron devices (vendor id 13364).

    I suspect that the keyboard could be detected as a mouse since its firmware allows to perform mouse actions. Cleaner ways to address the problem should be investigated, but this is a working temporary patch.

    Tested on MacOS 12.6.

    opened by bonassifabio 1
  • Filter non-keyboard events from Logitech G915 USB Dongle

    Filter non-keyboard events from Logitech G915 USB Dongle

    Hello, not an issue, but more of a question.

    I have a mac mini m1, I have two keyboards on it. One is in English and another one in Spanish. Mostly because I have a K400 that has a trackpad and makes my life easier to control my computer when I'm a bit far.

    My idea was that autokbisw would automatically switch between keyboards depending of which one was in use, but so far not much in terms of luck. If for example I start typing using my Spanish keyboard and manually switch to Spanish then go to to my English keyboard it will stay in Spanish. I have tried a few alterations, but so far nothing has really worked. I'm starting to think that this only works with laptops and a single external keyboard perhaps?

    thanks!

    help wanted 
    opened by fcastro86 5
Releases(1.4.3)
Owner
Ole Hüter
Full Stack Web Developer. 👨🏼‍💻 Cloud & DevOps Engineer. ☁️ PhD in Molecular Quantum Physics. 🚀
Ole Hüter
SwiftUIKeyPress - a package to make up for the lack of keyboard input in SwiftUI

SwiftUIKeyPress - a package to make up for the lack of keyboard input in SwiftUI

Underthestars-zhy 8 Oct 27, 2022
Slidden is an open source, customizable, iOS 8 keyboard, written in Swift

Slidden is an open source, customizable, iOS 8 keyboard, written in Swift. iOS 8 brought us the ability to create fully customizable keyboards, but do

Daniel Brim 595 Jan 5, 2023
IHKeyboardAvoiding is an elegant solution for keeping any UIView visible when the keyboard is being shown - no UIScrollView required!

IHKeyboardAvoiding An elegant solution for keeping any UIView visible when the keyboard is being shown Requirements IHKeyboardAvoiding Version Objecti

Idle Hands Apps 1.4k Dec 14, 2022
Codeless drop-in universal library allows to prevent issues of keyboard sliding up and cover UITextField/UITextView. Neither need to write any code nor any setup required and much more.

IQKeyboardManager While developing iOS apps, we often run into issues where the iPhone keyboard slides up and covers the UITextField/UITextView. IQKey

Mohd Iftekhar Qurashi 15.9k Jan 8, 2023
Codeless manager to hide keyboard by tapping on views for iOS written in Swift

KeyboardHideManager KeyboardHideManager - codeless manager to hide keyboard by tapping on views for iOS written in Swift. Structure Features Requireme

Bondar Yaroslav 55 Oct 19, 2022
⌨️ Add user-customizable global keyboard shortcuts to your macOS app in minutes

This package lets you add support for user-customizable global keyboard shortcuts to your macOS app in minutes. It's fully sandbox and Mac App Store c

Sindre Sorhus 1.1k Dec 29, 2022
Swift UIKit keyboard manager for iOS apps.

Typist Typist is a small, drop-in Swift UIKit keyboard manager for iOS apps. It helps you manage keyboard's screen presence and behavior without notif

Toto Tvalavadze 1.1k Dec 10, 2022
Suppress mouse & keyboard events on MacOSX. Baby-proof my Mac!

Suppress mouse & keyboard events on MacOSX Catches all events (mouse, keyboard, everything), and either consumes them (locked state) or passes them th

Albert Zeyer 6 Oct 21, 2022
KeyboardKit is a Swift library that helps you create custom keyboard extensions for iOS and ipadOS.

KeyboardKit is a Swift library that helps you create custom keyboard extensions for iOS and ipadOS.

KeyboardKit 900 Jan 9, 2023
QMK Agent is a macOS menubar application which sends commands to a QMK enabled keyboard

QMKagent QMK Agent is a macOS menubar application which sends commands to a QMK enabled keyboard Features System volume indicator using top row (Esc t

Mike Killewald 4 Apr 24, 2022
Best way to dismiss Keyboard in a View Controller iOS (Swift)

Best way to dismiss Keyboard in a View Controller iOS (Swift) First way: Implement UITextFieldDelegate’s textFieldShouldReturn method and dismiss curr

null 0 Dec 18, 2021
Showing / dismissing keyboard animation in simple UIViewController category.

RSKKeyboardAnimationObserver Easy way to handle iOS keyboard showing/dismissing. Introduction Working with iOS keyboard demands a lot of duplicated co

Ruslan Skorb 45 Jun 9, 2022
Objective-C library for tracking keyboard in iOS apps.

NgKeyboardTracker Objective-c library for tracking keyboard in iOS apps. Adding to your project If you are using CocoaPods, add to your Podfile: pod '

Meiwin Fu 808 Nov 17, 2022
A simple keyboard to use with numbers and, optionally, a decimal point.

MMNumberKeyboard A simple keyboard to use with numbers and, optionally, a decimal point. Installation From CocoaPods CocoaPods is a dependency manager

Matías Martínez 957 Nov 17, 2022
For less complicated keyboard event handling.

KeyboardObserver For less complicated keyboard event handling. Features Less complicated keyboard event handling. Do not use Notification , but event

Morita Naoki 163 May 24, 2022
A drop-in universal solution for moving text fields out of the way of the keyboard in iOS

TPKeyboardAvoiding A drop-in universal solution for moving text fields out of the way of the keyboard in iOS. Introduction There are a hundred and one

Michael Tyson 5.8k Dec 26, 2022
KeyboardMan helps you to make keyboard animation.

KeyboardMan We may need keyboard infomation from keyboard notifications to do animation. However, the approach is complicated and easy to make mistake

null 353 Apr 19, 2022
Emoji Keyboard SDK (iOS)

Makemoji SDK Makemoji is a free emoji keyboard for mobile apps. By installing our keyboard SDK every user of your app will instantly have access to ne

Makemoji 100 Nov 3, 2022
A Chinese keyboard for iOS that helps Chinese language learners remember tones.

ToneBoard ToneBoard is a Chinese keyboard for iOS that requires you to enter the correct tones while typing simplified Chinese with Pinyin. It is avai

Kevin Bell 7 Sep 27, 2022