We now take into account keypad keys
However, num lock is not accounted for. This still needs to be implemented.
This commit is contained in:
		
							parent
							
								
									5a76bd0c22
								
							
						
					
					
						commit
						33ed2af075
					
				| @ -110,8 +110,8 @@ func (backend *Backend) handleKeyPress ( | |||||||
| 	connection *xgbutil.XUtil, | 	connection *xgbutil.XUtil, | ||||||
| 	event xevent.KeyPressEvent, | 	event xevent.KeyPressEvent, | ||||||
| ) { | ) { | ||||||
| 	keyEvent := *event.KeyPressEvent | 	keyEvent    := *event.KeyPressEvent | ||||||
| 	button   := backend.keycodeToButton(keyEvent.Detail, keyEvent.State) | 	button, num := backend.keycodeToButton(keyEvent.Detail, keyEvent.State) | ||||||
| 	backend.callbackManager.RunPress (button, stone.Modifiers { | 	backend.callbackManager.RunPress (button, stone.Modifiers { | ||||||
| 		// FIXME these may not be correct in all cases | 		// FIXME these may not be correct in all cases | ||||||
| 		Shift:   (keyEvent.State & xproto.ModMaskShift)   > 0, | 		Shift:   (keyEvent.State & xproto.ModMaskShift)   > 0, | ||||||
| @ -120,6 +120,7 @@ func (backend *Backend) handleKeyPress ( | |||||||
| 		// Meta:    (keyEvent.State & xproto.??)       > 0, | 		// Meta:    (keyEvent.State & xproto.??)       > 0, | ||||||
| 		Super:   (keyEvent.State & xproto.ModMask4)       > 0, | 		Super:   (keyEvent.State & xproto.ModMask4)       > 0, | ||||||
| 		// Hyper:   (keyEvent.State & xproto.??)       > 0, | 		// Hyper:   (keyEvent.State & xproto.??)       > 0, | ||||||
|  | 		NumberPad: num, | ||||||
| 	}) | 	}) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -127,8 +128,8 @@ func (backend *Backend) handleKeyRelease ( | |||||||
| 	connection *xgbutil.XUtil, | 	connection *xgbutil.XUtil, | ||||||
| 	event xevent.KeyReleaseEvent, | 	event xevent.KeyReleaseEvent, | ||||||
| ) { | ) { | ||||||
| 	keyEvent := *event.KeyReleaseEvent | 	keyEvent  := *event.KeyReleaseEvent | ||||||
| 	button   := backend.keycodeToButton(keyEvent.Detail, keyEvent.State) | 	button, _ := backend.keycodeToButton(keyEvent.Detail, keyEvent.State) | ||||||
| 	backend.callbackManager.RunRelease(button) | 	backend.callbackManager.RunRelease(button) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -71,11 +71,51 @@ var buttonCodeTable = map[xproto.Keysym] stone.Button { | |||||||
| 	0xFF20: stone.KeyDead, | 	0xFF20: stone.KeyDead, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | var keypadCodeTable = map[xproto.Keysym] stone.Button { | ||||||
|  | 	0xff80: stone.Button(' '), | ||||||
|  | 	0xff89: stone.KeyTab, | ||||||
|  | 	0xff8d: stone.KeyEnter, | ||||||
|  | 	0xff91: stone.KeyF1, | ||||||
|  | 	0xff92: stone.KeyF2, | ||||||
|  | 	0xff93: stone.KeyF3, | ||||||
|  | 	0xff94: stone.KeyF4, | ||||||
|  | 	0xff95: stone.KeyHome, | ||||||
|  | 	0xff96: stone.KeyLeft, | ||||||
|  | 	0xff97: stone.KeyUp, | ||||||
|  | 	0xff98: stone.KeyRight, | ||||||
|  | 	0xff99: stone.KeyDown, | ||||||
|  | 	0xff9a: stone.KeyPageUp, | ||||||
|  | 	0xff9b: stone.KeyPageDown, | ||||||
|  | 	0xff9c: stone.KeyEnd, | ||||||
|  | 	0xff9d: stone.KeyHome, | ||||||
|  | 	0xff9e: stone.KeyInsert, | ||||||
|  | 	0xff9f: stone.KeyDelete, | ||||||
|  | 	0xffbd: stone.Button('='), | ||||||
|  | 	0xffaa: stone.Button('*'), | ||||||
|  | 	0xffab: stone.Button('+'), | ||||||
|  | 	0xffac: stone.Button(','), | ||||||
|  | 	0xffad: stone.Button('-'), | ||||||
|  | 	0xffae: stone.Button('.'), | ||||||
|  | 	0xffaf: stone.Button('/'), | ||||||
|  | 
 | ||||||
|  | 	0xffb0: stone.Button('0'), | ||||||
|  | 	0xffb1: stone.Button('1'), | ||||||
|  | 	0xffb2: stone.Button('2'), | ||||||
|  | 	0xffb3: stone.Button('3'), | ||||||
|  | 	0xffb4: stone.Button('4'), | ||||||
|  | 	0xffb5: stone.Button('5'), | ||||||
|  | 	0xffb6: stone.Button('6'), | ||||||
|  | 	0xffb7: stone.Button('7'), | ||||||
|  | 	0xffb8: stone.Button('8'), | ||||||
|  | 	0xffb9: stone.Button('9'), | ||||||
|  | } | ||||||
|  | 
 | ||||||
| func (backend *Backend) keycodeToButton ( | func (backend *Backend) keycodeToButton ( | ||||||
| 	keycode xproto.Keycode, | 	keycode xproto.Keycode, | ||||||
| 	state   uint16, | 	state   uint16, | ||||||
| ) ( | ) ( | ||||||
| 	button stone.Button, | 	button    stone.Button, | ||||||
|  | 	numberPad bool, | ||||||
| ) { | ) { | ||||||
| 	// FIXME: also set shift to true if the lock modifier is on and the lock | 	// FIXME: also set shift to true if the lock modifier is on and the lock | ||||||
| 	// modifier is interpreted as shiftLock | 	// modifier is interpreted as shiftLock | ||||||
| @ -168,14 +208,17 @@ func (backend *Backend) keycodeToButton ( | |||||||
| 		selectedRune   = symbol2Rune | 		selectedRune   = symbol2Rune | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// look up in table | 	// look up in control code table | ||||||
| 	var isControl bool | 	var isControl bool | ||||||
| 	button, isControl = buttonCodeTable[selectedKeysym] | 	button, isControl = buttonCodeTable[selectedKeysym] | ||||||
|  | 	if isControl { return } | ||||||
| 
 | 
 | ||||||
| 	// if it wasn't found,  | 	// look up in keypad table | ||||||
| 	if !isControl { | 	button, numberPad = keypadCodeTable[selectedKeysym] | ||||||
| 		button = stone.Button(selectedRune) | 	if numberPad { return } | ||||||
| 	} | 
 | ||||||
|  | 	// otherwise, use the rune | ||||||
|  | 	button = stone.Button(selectedRune) | ||||||
| 	 | 	 | ||||||
| 	return | 	return | ||||||
| } | } | ||||||
|  | |||||||
							
								
								
									
										34
									
								
								input.go
									
									
									
									
									
								
							
							
						
						
									
										34
									
								
								input.go
									
									
									
									
									
								
							| @ -44,20 +44,20 @@ const ( | |||||||
| 	 | 	 | ||||||
| 	KeyDelete       Button = 127 | 	KeyDelete       Button = 127 | ||||||
| 	 | 	 | ||||||
| 	MouseButton1           Button = 128 | 	MouseButton1       Button = 128 | ||||||
| 	MouseButton2           Button = 129 | 	MouseButton2       Button = 129 | ||||||
| 	MouseButton3           Button = 130 | 	MouseButton3       Button = 130 | ||||||
| 	MouseButton4           Button = 131 | 	MouseButton4       Button = 131 | ||||||
| 	MouseButton5           Button = 132 | 	MouseButton5       Button = 132 | ||||||
| 	MouseButton6           Button = 133 | 	MouseButton6       Button = 133 | ||||||
| 	MouseButton7           Button = 134 | 	MouseButton7       Button = 134 | ||||||
| 	MouseButton8           Button = 135 | 	MouseButton8       Button = 135 | ||||||
| 	MouseButton9           Button = 136 | 	MouseButton9       Button = 136 | ||||||
| 	MouseButtonLeft        Button = MouseButton1 | 	MouseButtonLeft    Button = MouseButton1 | ||||||
| 	MouseButtonMiddle      Button = MouseButton2 | 	MouseButtonMiddle  Button = MouseButton2 | ||||||
| 	MouseButtonRight       Button = MouseButton3 | 	MouseButtonRight   Button = MouseButton3 | ||||||
| 	MouseButtonBack        Button = MouseButton8 | 	MouseButtonBack    Button = MouseButton8 | ||||||
| 	MouseButtonForward     Button = MouseButton9 | 	MouseButtonForward Button = MouseButton9 | ||||||
| 	 | 	 | ||||||
| 	KeyF1  Button = 144 | 	KeyF1  Button = 144 | ||||||
| 	KeyF2  Button = 145 | 	KeyF2  Button = 145 | ||||||
| @ -94,4 +94,10 @@ type Modifiers struct { | |||||||
| 	Meta    bool | 	Meta    bool | ||||||
| 	Super   bool | 	Super   bool | ||||||
| 	Hyper   bool | 	Hyper   bool | ||||||
|  | 
 | ||||||
|  | 	// NumberPad does not represent a key, but it behaves like one. If it is | ||||||
|  | 	// set to true, the button was pressed on the number pad. It is treated | ||||||
|  | 	// as a modifier key because if you don't care whether a key was pressed | ||||||
|  | 	// on the number pad or not, you can just ignore this value. | ||||||
|  | 	NumberPad bool | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user