Skip to content

Commit

Permalink
Merge pull request #10 from fhs/keycode
Browse files Browse the repository at this point in the history
Add more keycodes for X11
  • Loading branch information
ktye committed Feb 19, 2019
2 parents 718affc + ac51d85 commit 3c3ad83
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
5 changes: 5 additions & 0 deletions events.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ func (d *Display) eventLoop(errch chan<- error) {
if sendKey == '\r' {
sendKey = '\n'
}
if e.Modifiers == 0x2 { // Ctrl
if r, ok := ctrlMods[sendKey]; ok {
sendKey = r
}
}
// fmt.Printf("shiny: key: %x %v\n", sendKey, e)
d.keyboard.C <- sendKey
}
Expand Down
38 changes: 26 additions & 12 deletions keyboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,40 @@ const (
//KeyAlt = KeyFn | 0x15
//KeyShift = KeyFn | 0x16
//KeyCtl = KeyFn | 0x17
//KeyBackspace = 0x08
KeyDelete = 0x7F
KeyEscape = 0x1b
KeyBackspace = 0x08
KeyDelete = 0x7F
KeyEscape = 0x1b
//KeyEOF = 0x04
KeyCmd = 0xF100
)

// Keymap maps from key event codes to runes, that duit expects.
var keymap = map[key.Code]rune{
key.CodeHome: KeyHome,
key.CodeUpArrow: KeyUp,
key.CodePageUp: KeyPageUp,
key.CodeLeftArrow: KeyLeft,
key.CodeRightArrow: KeyRight,
key.CodeDownArrow: KeyDown,
key.CodePageDown: KeyPageDown,
key.CodeEnd: KeyEnd,
key.CodeHome: KeyHome,
key.CodeUpArrow: KeyUp,
key.CodePageUp: KeyPageUp,
key.CodeLeftArrow: KeyLeft,
key.CodeRightArrow: KeyRight,
key.CodeDownArrow: KeyDown,
key.CodePageDown: KeyPageDown,
key.CodeInsert: KeyInsert,
key.CodeEnd: KeyEnd,
key.CodeDeleteBackspace: KeyBackspace,
//key.CodeDelete: KeyDelete,
key.CodeEscape: KeyEscape,
key.CodeDeleteForward: KeyDelete,
key.CodeEscape: KeyEscape,
//key.CodeCmd: KeyCmd,
key.CodeReturnEnter: '\n',
key.CodeTab: '\t',
}

var ctrlMods = map[rune]rune{
'a': 0x01, // ^a: beginning of line
'e': 0x05, // ^e: end of line
'f': 0x06, // ^f: complete
'h': 0x08, // ^h: erase character
'u': 0x15, // ^u: erase line
'w': 0x17, // ^w: erase word
}

// Keyboardctl is the source of keyboard events.
Expand Down

0 comments on commit 3c3ad83

Please sign in to comment.