Skip to content

Instantly share code, notes, and snippets.

@ShikiOkasaka
Created May 26, 2022 14:49
Show Gist options
  • Save ShikiOkasaka/d4ffc20332bb61fc2b342a81a3978678 to your computer and use it in GitHub Desktop.
Save ShikiOkasaka/d4ffc20332bb61fc2b342a81a3978678 to your computer and use it in GitHub Desktop.
This code doen't work on Wayland for getting Capslock state.
#!/usr/bin/python3
import gi
gi.require_version('Gdk', '4.0')
gi.require_version('Gtk', '4.0')
from gi.repository import Gtk, Gdk, GLib, GObject
def on_keyboard_notify(keyboard, data):
print(keyboard.get_caps_lock_state())
def main():
display = Gdk.Display.get_default()
seat = display.get_default_seat()
keyboard = seat.get_keyboard()
print(keyboard.get_caps_lock_state())
keyboard.connect('notify::caps-lock-state', on_keyboard_notify)
loop = GLib.MainLoop()
loop.run()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment