Added String method to Modifiers
This commit is contained in:
parent
e114c6d700
commit
aa46cada1f
@ -67,10 +67,11 @@ func main() {
|
||||
xevent.KeyPressFun(
|
||||
func(X *xgbutil.XUtil, e xevent.KeyPressEvent) {
|
||||
symbol, character := xgbkb.KeycodeToKeysym( e.Detail, e.State)
|
||||
modifiers := xgbkb.StateToModifiers(e.State)
|
||||
if unicode.IsPrint(character) {
|
||||
log.Printf("0x%04X | '%s'\n", symbol, string(character))
|
||||
log.Printf("0x%04X | '%s' %v\n", symbol, string(character), modifiers)
|
||||
} else {
|
||||
log.Printf("0x%04X |\n", symbol)
|
||||
log.Printf("0x%04X | %v\n", symbol, modifiers)
|
||||
}
|
||||
|
||||
if keybind.KeyMatch(X, "Escape", e.State, e.Detail) {
|
||||
|
19
keyboard.go
19
keyboard.go
@ -61,6 +61,25 @@ type Modifiers struct {
|
||||
Hyper bool
|
||||
}
|
||||
|
||||
// String returns a human-readable comma-separated list of all active modifiers.
|
||||
func (modifiers Modifiers) String () (out string) {
|
||||
add := func (name string) {
|
||||
if out != "" {
|
||||
out += ", "
|
||||
}
|
||||
out += name
|
||||
}
|
||||
if modifiers.Hyper { add("Hyper") }
|
||||
if modifiers.Super { add("Super") }
|
||||
if modifiers.Meta { add("Meta") }
|
||||
if modifiers.Alt { add("Alt") }
|
||||
if modifiers.ModeSwitch { add("ModeSwitch") }
|
||||
if modifiers.NumLock { add("NumLock") }
|
||||
if modifiers.ShiftLock { add("ShiftLock") }
|
||||
if modifiers.CapsLock { add("CapsLock") }
|
||||
return
|
||||
}
|
||||
|
||||
// StateToModifiers converts a modifier state given by a keyboard or mouse event
|
||||
// to a Modifiers struct.
|
||||
func StateToModifiers (state uint16) Modifiers {
|
||||
|
Loading…
Reference in New Issue
Block a user