2
2
Package keybind provides an easy to use interface to assign callback functions
3
3
to human readable key sequences.
4
4
5
- Working with the X keyboard encoding is not an easy task, and the keybind
5
+ Working with the X keyboard encoding is not an easy task, and the keybind
6
6
package attempts to encapsulate much of the complexity. Namely, the keybind
7
7
package exports two function types: KeyPressFun and KeyReleaseFun. Values of
8
8
these types are functions, and have a method called 'Connect' that attaches
@@ -44,30 +44,30 @@ shift---are pressed along with the 't' key.
44
44
45
45
When to issue a passive grab
46
46
47
- One of the parameters of the 'Connect' method is whether to issue a passive
47
+ One of the parameters of the 'Connect' method is whether to issue a passive
48
48
grab or not. A passive grab is useful when you need to respond to a key press
49
- on some parent window (like the root window) without actually focusing that
50
- window. Not using a passive grab is useful when you only need to read key
49
+ on some parent window (like the root window) without actually focusing that
50
+ window. Not using a passive grab is useful when you only need to read key
51
51
presses when the window is focused.
52
52
53
53
For more information on the semantics of passive grabs, please see
54
54
http://tronche.com/gui/x/xlib/input/XGrabKey.html.
55
55
56
- Also, by default, when issuing a grab on a particular (modifiers, keycode)
57
- tuple, several grabs are actually made. In particular, for each grab requested,
56
+ Also, by default, when issuing a grab on a particular (modifiers, keycode)
57
+ tuple, several grabs are actually made. In particular, for each grab requested,
58
58
another grab is made with the "num lock" mask, another grab is made with the
59
- "caps lock" mask, and another grab is made with both the "num lock" and "caps
59
+ "caps lock" mask, and another grab is made with both the "num lock" and "caps
60
60
locks" masks. This allows key events to be reported regardless of whether
61
61
caps lock or num lock is enabled.
62
62
63
- The extra masks added can be modified by changing the xevent.IgnoreMods slice.
64
- If you modify xevent.IgnoreMods, it should be modified once on program startup
65
- (i.e., before any key or mouse bindings are established) and never modified
63
+ The extra masks added can be modified by changing the xevent.IgnoreMods slice.
64
+ If you modify xevent.IgnoreMods, it should be modified once on program startup
65
+ (i.e., before any key or mouse bindings are established) and never modified
66
66
again.
67
67
68
68
Key bindings on the root window example
69
69
70
- To run a particular function whenever the 'Mod4-Control-Shift-t' key
70
+ To run a particular function whenever the 'Mod4-Control-Shift-t' key
71
71
combination is pressed (mod4 is typically the 'super' or 'windows' key, but can
72
72
vary based on your system), use something like:
73
73
@@ -83,8 +83,8 @@ window will only be reported when the root window has focus if no grab exists.
83
83
84
84
Key bindings on a window you create example
85
85
86
- This code snippet attaches an event handler to some window you've created
87
- without using a grab. Thus, the function will only be activated when the key
86
+ This code snippet attaches an event handler to some window you've created
87
+ without using a grab. Thus, the function will only be activated when the key
88
88
sequence is pressed and your window has focus.
89
89
90
90
keybind.Initialize(XUtilValue) // call once before using keybind package
@@ -95,23 +95,23 @@ sequence is pressed and your window has focus.
95
95
96
96
Run a function on all key press events example
97
97
98
- This code snippet actually does *not* use the keybind package, but illustrates
99
- how the Key{Press,Release} event handlers in the xevent package can still be
100
- useful. Namely, the keybind package discriminates among events depending upon
101
- the key sequences pressed, whereas the xevent package is more general: it can
98
+ This code snippet actually does *not* use the keybind package, but illustrates
99
+ how the Key{Press,Release} event handlers in the xevent package can still be
100
+ useful. Namely, the keybind package discriminates among events depending upon
101
+ the key sequences pressed, whereas the xevent package is more general: it can
102
102
only discriminate at the event level.
103
103
104
104
xevent.KeyPressFun(
105
105
func(X *xgbutil.XUtil, ev xevent.KeyPressEvent) {
106
106
// do something when any key is pressed
107
107
}).Connect(XUtilValue, your-window-id)
108
108
109
- This is the kind of handler you might use to capture all key press events.
110
- (i.e., if you have a text box for a user to type in.) Additionally, if you're
111
- using this sort of event handler, keybind.LookupString will probably be of some
112
- use. Its contract is that given a (modifiers, keycode) tuple
113
- (information found in all Key{Press,Release} events) it will return a string
114
- representation of the key pressed. We can modify the above example slightly to
109
+ This is the kind of handler you might use to capture all key press events.
110
+ (i.e., if you have a text box for a user to type in.) Additionally, if you're
111
+ using this sort of event handler, keybind.LookupString will probably be of some
112
+ use. Its contract is that given a (modifiers, keycode) tuple
113
+ (information found in all Key{Press,Release} events) it will return a string
114
+ representation of the key pressed. We can modify the above example slightly to
115
115
echo the key pressed:
116
116
117
117
xevent.KeyPressFun(
@@ -122,7 +122,7 @@ echo the key pressed:
122
122
123
123
More examples
124
124
125
- Complete working examples can be found in the examples directory of xgbutil. Of
125
+ Complete working examples can be found in the examples directory of xgbutil. Of
126
126
particular interest are probably 'keypress-english' and 'simple-keybinding'.
127
127
128
128
*/
0 commit comments