Skip to content

Commit

Permalink
#391: basic support for keymap on osx using a hard-coded lookup table…
Browse files Browse the repository at this point in the history
…, and:

* allow all positive values as keycodes ('A' is keycode 0 on OSX..)
* remove unused "parse_options" in win32 keyboard code

git-svn-id: https://xpra.org/svn/Xpra/trunk@12393 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Apr 16, 2016
1 parent ee87e89 commit 33f4982
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 4 deletions.
140 changes: 140 additions & 0 deletions src/xpra/platform/darwin/keyboard_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
# coding=utf8
# This file is part of Xpra.
# Copyright (C) 2014 Antoine Martin <antoine@devloop.org.uk>
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.

from xpra.log import Logger
log = Logger("keyboard", "osx")

from xpra.server.keyboard_config_base import KeyboardConfigBase


class KeyboardConfig(KeyboardConfigBase):

def __init__(self):
KeyboardConfigBase.__init__(self)

def __repr__(self):
return "osx.KeyboardConfig"


def get_keycode(self, client_keycode, keyname, modifiers):
global KEYCODES
keycode = KEYCODES.get(keyname, -1)
if keycode==-1:
keycode = KEYCODES.get(keyname.upper(), -1)
log("get_keycode%s=%s", (client_keycode, keyname, modifiers), keycode)
return keycode

#we currently assume that all key events are sent using X11 names,
#so we need to translate them to osx keys
#this list has been generated using:
#$cat /Developer/Examples/Speech/Recognition/fauxTunes/Virtual\ Key\ Code\ Mappings.txt | awk '{print " \""$1"\" : "$2$3","}'
KEYCODES = {
#Standardkeys
"A" : 0,
"B" : 11,
"C" : 8,
"D" : 2,
"E" : 14,
"F" : 3,
"G" : 5,
"H" : 4,
"I" : 34,
"J" : 38,
"K" : 40,
"L" : 37,
"M" : 46,
"N" : 45,
"O" : 31,
"P" : 35,
"Q" : 12,
"R" : 15,
"S" : 1,
"T" : 17,
"U" : 32,
"V" : 9,
"W" : 13,
"X" : 7,
"Y" : 16,
"Z" : 6,
"1" : 18,
"2" : 19,
"3" : 20,
"4" : 21,
"5" : 23,
"6" : 22,
"7" : 26,
"8" : 28,
"9" : 25,
"0" : 29,
"-" : 27,
"=" : 24,
"[" : 33,
"]" : 30,
"\\" : 42,
";" : 41,
"'" : 39,
"," : 43,
"." : 47,
"/" : 44,
"Delete" : 51,
"Return" : 35,
"Tab" : 48,
"Caps_Lock" : 57,
"space" : 9,
#Numeric pad keys:
"KP_1" : 83,
"KP_2" : 84,
"KP_3" : 85,
"KP_4" : 86,
"KP_5" : 87,
"KP_6" : 88,
"KP_7" : 89,
"KP_8" : 91,
"KP_9" : 92,
"KP_0" : 82,
"KP_Decimal" : 65,
"equal" : 81,
"KP_Divide" : 75,
"KP_Multiply" : 67,
"KP_Subtract" : 78,
"KP_Add" : 69,
"clear" : 71,
"KP_Enter" : 76,
#Navigation keys:
"Down" : 125,
"Up" : 126,
"Right" : 124,
"Left" : 123,
"Prior" : 116, #Page Up
"Next" : 121, #Page Down
"Home" : 115,
"End" : 119,
"Insert" : 114, #help
"Delete" : 117,
#Function keys:
"F1" : 122,
"F2" : 120,
"F3" : 99,
"F4" : 119,
"F5" : 96,
"F6" : 57,
"F7" : 98,
"F8" : 100,
"F9" : 101,
"F10" : 109,
"F11" : 103,
"F12" : 111,
"F13" : 105,
"F14" : 107,
"F15" : 113,
#Modifier keys:
"Shift_L" : 56,
"Control_L" : 59,
"Alt_L" : 58, #option
"Super_L" : 55, #apple
}

log("KEYCODES: %s", KEYCODES)
3 changes: 0 additions & 3 deletions src/xpra/platform/win32/keyboard_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ def __repr__(self):
return "win32.KeyboardConfig"


def parse_options(self, props):
return KeyboardConfigBase.parse_options(self, props)

def get_keycode(self, client_keycode, keyname, modifiers):
keycode = KEYCODES.get(keyname, -1)
log("get_keycode%s=%s", (client_keycode, keyname, modifiers), keycode)
Expand Down
2 changes: 1 addition & 1 deletion src/xpra/server/server_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2354,7 +2354,7 @@ def _process_key_action(self, proto, packet):
ss.make_keymask_match(modifiers, keycode, ignored_modifier_keynames=[keyname])
#negative keycodes are used for key events without a real keypress/unpress
#for example, used by win32 to send Caps_Lock/Num_Lock changes
if keycode>0:
if keycode>=0:
self._handle_key(wid, pressed, keyname, keyval, keycode, modifiers)
ss.user_event()

Expand Down

0 comments on commit 33f4982

Please sign in to comment.