Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Fast Fn Language Switcher for macOS

Switch keyboard layouts with the Fn/Globe key and start typing immediately—without waiting for macOS to finish its built-in input-source animation or delay.

Why

macOS can assign “Change Input Source” to the Fn/Globe key, but the change may arrive late enough that the first quickly typed character uses the old layout. This Hammerspoon script handles the transition synchronously:

  • Tap Fn to select the next enabled keyboard layout.
  • If a printable key arrives before Fn is released, switch first and deliver that physical key in the new layout.
  • Keep Fn+F1–F12, arrows, Return, Tab, Delete, and combinations with other modifiers working normally.

The implementation never deletes keyboard events and never posts synthetic keyboard events. When necessary, it only removes the Fn flag from the original printable-key event before allowing that event to continue.

Requirements

  • macOS
  • Two or more keyboard layouts enabled in System Settings → Keyboard → Text Input
  • Hammerspoon with Accessibility permission

Install

  1. Install and launch Hammerspoon:

    brew install --cask hammerspoon
  2. In System Settings → Privacy & Security → Accessibility, enable Hammerspoon.

  3. In System Settings → Keyboard, set “Press Fn/Globe key to” → “Do Nothing.” This prevents macOS and the script from both switching the layout.

  4. Use this repository's init.lua as ~/.hammerspoon/init.lua:

    mkdir -p ~/.hammerspoon
    cp init.lua ~/.hammerspoon/init.lua

    If you already have a Hammerspoon configuration, copy the script into it instead of overwriting your existing file.

  5. From the Hammerspoon menu-bar icon, choose Reload Config. You should see “Fast Fn language switching is active.”

Optionally enable Launch Hammerspoon at login in Hammerspoon Settings.

Use

  • Tap Fn/Globe: switch to the next enabled keyboard layout.
  • Fn then a printable key, without waiting: switch first, then type that key in the new layout.
  • Fn+F1–F12 or another non-printable key: retain normal Fn behavior and do not switch layouts.
  • Fn plus another modifier: retain the original shortcut behavior and do not switch layouts.

With more than two enabled keyboard layouts, Fn cycles through them in the order returned by macOS.

Emergency stop

Press Control+Option+Command+Escape (⌃⌥⌘Esc) to stop the switcher until the Hammerspoon configuration is reloaded or Hammerspoon restarts.

Limitations

  • Hammerspoon cannot observe keyboard events while macOS Secure Input is active, such as in some password fields.
  • Keyboard utilities that also remap Fn may conflict with this script.
  • The physical keycode set targets standard ANSI/ISO Mac keyboard character positions.

License

MIT

About

Instant macOS input-source switching with the Fn/Globe key via Hammerspoon.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages