diff --git a/keyboard.go b/keyboard.go index 7db254a..964731b 100644 --- a/keyboard.go +++ b/keyboard.go @@ -48,6 +48,34 @@ func Initialize (connection *xgbutil.XUtil) { modifierMasks.alt = KeysymToMask(0xffe9) } +// Modifiers lists which modifier keys are toggled on or being pressed. +type Modifiers struct { + CapsLock bool + ShiftLock bool + NumLock bool + ModeSwitch bool + + Alt bool + Meta bool + Super bool + Hyper bool +} + +// StateToModifiers converts a modifier state given by a keyboard or mouse event +// to a Modifiers struct. +func StateToModifiers (state uint16) Modifiers { + return Modifiers { + CapsLock: 0 < state & modifierMasks.capsLock, + ShiftLock: 0 < state & modifierMasks.shiftLock, + NumLock: 0 < state & modifierMasks.numLock, + ModeSwitch: 0 < state & modifierMasks.modeSwitch, + Alt: 0 < state & modifierMasks.alt, + Meta: 0 < state & modifierMasks.meta, + Super: 0 < state & modifierMasks.super, + Hyper: 0 < state & modifierMasks.hyper, + } +} + // KeysymToKeycode converts an X keysym to an X keycode, instead of the other // way around. func KeysymToKeycode (