Beispiel #1
0
 def process_key_event(self, send_key_action_cb, wid, key_event):
     """ Caps_Lock and Num_Lock don't work properly: they get reported more than once,
         they are reported as not pressed when the key is down, etc
         So we just ignore those and rely on the list of "modifiers" passed
         with each keypress to let the server set them for us when needed.
     """
     if key_event.keyval==2**24-1 and key_event.keyname=="VoidSymbol":
         return
     #self.modifier_mappings = None       #{'control': [(37, 'Control_L'), (105, 'Control_R')], 'mod1':
     #self.modifier_keys = {}             #{"Control_L" : "control", ...}
     #self.modifier_keycodes = {}         #{"Control_R" : [105], ...}
     #self.modifier_keycodes = {"ISO_Level3_Shift": [108]}
     #we can only deal with 'Alt_R' and simulate AltGr (ISO_Level3_Shift)
     #if we have modifier_mappings
     if key_event.keyname=="Alt_R" and len(self.modifier_mappings)>0:
         keyname = "ISO_Level3_Shift"
         altgr_keycodes = self.modifier_keycodes.get(keyname, [])
         if len(altgr_keycodes)>0:
             self.emulate_altgr = key_event.pressed
             if key_event.pressed and self.last_key_event_sent:
                 #check for spurious control and undo it
                 last_wid, last_key_event = self.last_key_event_sent
                 if last_wid==wid and last_key_event.keyname=="Control_L" and last_key_event.pressed==True:
                     #undo it:
                     last_key_event.pressed = False
                     KeyboardBase.process_key_event(self, send_key_action_cb, last_wid, last_key_event)
             self.AltGr_modifiers(key_event.modifiers, not key_event.pressed)
     self.last_key_event_sent = (wid, key_event)
     #now fallback to default behaviour:
     KeyboardBase.process_key_event(self, send_key_action_cb, wid, key_event)
Beispiel #2
0
 def send_delayed_key(self):
     #timeout: this must be a real one, send it now
     dk = self.delayed_event
     log("send_delayed_key() delayed_event=%s", dk)
     if dk:
         self.delayed_event = None
         altgr = win32api.GetKeyState(win32con.VK_RMENU) not in (0, 1)
         if altgr:
             KeyboardBase.process_key_event(self, *dk)
Beispiel #3
0
 def send_delayed_key(self):
     #timeout: this must be a real one, send it now
     dk = self.delayed_event
     log("send_delayed_key() delayed_event=%s", dk)
     if dk:
         self.delayed_event = None
         altgr = win32api.GetKeyState(win32con.VK_RMENU) not in (0, 1)
         if altgr:
             KeyboardBase.process_key_event(self, *dk)
Beispiel #4
0
 def process_key_event(self, send_key_action_cb, wid, key_event):
     """ Caps_Lock and Num_Lock don't work properly: they get reported more than once,
         they are reported as not pressed when the key is down, etc
         So we just ignore those and rely on the list of "modifiers" passed
         with each keypress to let the server set them for us when needed.
     """
     if key_event.keyval == 2**24 - 1 and key_event.keyname == "VoidSymbol":
         log("process_key_event: ignoring %s", key_event)
         return
     #self.modifier_mappings = None       #{'control': [(37, 'Control_L'), (105, 'Control_R')], 'mod1':
     #self.modifier_keys = {}             #{"Control_L" : "control", ...}
     #self.modifier_keycodes = {}         #{"Control_R" : [105], ...}
     #self.modifier_keycodes = {"ISO_Level3_Shift": [108]}
     #we can only deal with 'Alt_R' and simulate AltGr (ISO_Level3_Shift)
     #if we have modifier_mappings
     if EMULATE_ALTGR and self.altgr_modifier and len(
             self.modifier_mappings) > 0:
         rmenu = GetKeyState(win32con.VK_RMENU)
         if key_event.keyname == "Control_L":
             log(
                 "process_key_event: %s pressed=%s, with GetKeyState(VK_RMENU)=%s",
                 key_event.keyname, key_event.pressed, rmenu)
             #AltGr is often preceded by a spurious "Control_L" event
             #delay this one a little bit so we can skip it if an "AltGr" does come through next:
             if key_event.pressed:
                 if rmenu in (0, 1):
                     self.delayed_event = (send_key_action_cb, wid,
                                           key_event)
                     #needed for altgr emulation timeouts:
                     from xpra.gtk_common.gobject_compat import import_glib
                     glib = import_glib()
                     glib.timeout_add(EMULATE_ALTGR_CONTROL_KEY_DELAY,
                                      self.send_delayed_key)
                 return
             if not key_event.pressed and rmenu not in (0, 1):
                 #unpressed: could just skip it?
                 #(but maybe the real one got pressed.. and this would get it stuck)
                 pass
         if key_event.keyname == "Alt_R":
             log(
                 "process_key_event: Alt_R pressed=%s, with GetKeyState(VK_RMENU)=%s",
                 key_event.pressed, rmenu)
             if rmenu in (0, 1) and key_event.pressed:
                 #cancel "Control_L" if one was due:
                 self.delayed_event = None
             #modify the key event so that it will only trigger the modifier update,
             #and not not the key event itself:
             key_event.string = ""
             key_event.keyname = ""
             key_event.group = -1
             key_event.keyval = -1
             key_event.keycode = -1
             self.AltGr_modifiers(key_event.modifiers)
     self.send_delayed_key()
     KeyboardBase.process_key_event(self, send_key_action_cb, wid,
                                    key_event)
Beispiel #5
0
 def send_delayed_key(self):
     #timeout: this must be a real one, send it now
     dk = self.delayed_event
     log("send_delayed_key() delayed_event=%s", dk)
     if dk:
         self.delayed_event = None
         rmenu = GetKeyState(win32con.VK_RMENU)
         log("send_delayed_key() GetKeyState(VK_RMENU)=%s", rmenu)
         if rmenu not in (0, 1):
             KeyboardBase.process_key_event(self, *dk)
Beispiel #6
0
 def send_delayed_key(self):
     #timeout: this must be a real one, send it now
     dk = self.delayed_event
     if dk:
         self.delayed_event = None
         altgr = win32api.GetKeyState(win32con.VK_RMENU) not in (0, 1)
         if altgr:
             send_key_action_cb, wid, key_event = dk
             KeyboardBase.process_key_event(self, send_key_action_cb, wid,
                                            key_event)
Beispiel #7
0
 def process_key_event(self, send_key_action_cb, wid, key_event):
     """ Caps_Lock and Num_Lock don't work properly: they get reported more than once,
         they are reported as not pressed when the key is down, etc
         So we just ignore those and rely on the list of "modifiers" passed
         with each keypress to let the server set them for us when needed.
     """
     if key_event.keyval==2**24-1 and key_event.keyname=="VoidSymbol":
         log("process_key_event: ignoring %s", key_event)
         return
     #self.modifier_mappings = None       #{'control': [(37, 'Control_L'), (105, 'Control_R')], 'mod1':
     #self.modifier_keys = {}             #{"Control_L" : "control", ...}
     #self.modifier_keycodes = {}         #{"Control_R" : [105], ...}
     #self.modifier_keycodes = {"ISO_Level3_Shift": [108]}
     #we can only deal with 'Alt_R' and simulate AltGr (ISO_Level3_Shift)
     #if we have modifier_mappings
     if EMULATE_ALTGR and self.altgr_modifier and len(self.modifier_mappings)>0:
         rmenu = win32api.GetKeyState(win32con.VK_RMENU)
         if key_event.keyname=="Control_L":
             log("process_key_event: %s pressed=%s, with GetKeyState(VK_RMENU)=%s", key_event.keyname, key_event.pressed, rmenu)
             #AltGr is often preceded by a spurious "Control_L" event
             #delay this one a little bit so we can skip it if an "AltGr" does come through next:
             if key_event.pressed:
                 if rmenu in (0, 1):
                     self.delayed_event = (send_key_action_cb, wid, key_event)
                     glib.timeout_add(EMULATE_ALTGR_CONTROL_KEY_DELAY, self.send_delayed_key)
                 return
             if not key_event.pressed and rmenu not in (0, 1):
                 #unpressed: could just skip it?
                 #(but maybe the real one got pressed.. and this would get it stuck)
                 pass
         if key_event.keyname=="Alt_R":
             log("process_key_event: Alt_R pressed=%s, with GetKeyState(VK_RMENU)=%s", key_event.pressed, rmenu)
             if rmenu in (0, 1) and key_event.pressed:
                 #cancel "Control_L" if one was due:
                 self.delayed_event = None
             #modify the key event so that it will only trigger the modifier update,
             #and not not the key event itself:
             key_event.string = ""
             key_event.keyname = ""
             key_event.group = -1
             key_event.keyval = -1
             key_event.keycode = -1
             self.AltGr_modifiers(key_event.modifiers)
     self.send_delayed_key()
     KeyboardBase.process_key_event(self, send_key_action_cb, wid, key_event)
Beispiel #8
0
 def process_key_event(self, send_key_action_cb, wid, key_event):
     """ Caps_Lock and Num_Lock don't work properly: they get reported more than once,
         they are reported as not pressed when the key is down, etc
         So we just ignore those and rely on the list of "modifiers" passed
         with each keypress to let the server set them for us when needed.
     """
     log("win32.process_key_event(%s, %s, %s)", send_key_action_cb, wid,
         key_event)
     if key_event.keyval == 2**24 - 1 and key_event.keyname == "VoidSymbol":
         return
     #self.modifier_mappings = None       #{'control': [(37, 'Control_L'), (105, 'Control_R')], 'mod1':
     #self.modifier_keys = {}             #{"Control_L" : "control", ...}
     #self.modifier_keycodes = {}         #{"Control_R" : [105], ...}
     #self.modifier_keycodes = {"ISO_Level3_Shift": [108]}
     #we can only deal with 'Alt_R' and simulate AltGr (ISO_Level3_Shift)
     #if we have modifier_mappings
     if key_event.keyname == "Alt_R" and len(self.modifier_mappings) > 0:
         keyname = "ISO_Level3_Shift"
         altgr_keycodes = self.modifier_keycodes.get(keyname, [])
         if len(altgr_keycodes) > 0:
             self.emulate_altgr = key_event.pressed
             if key_event.pressed and self.last_key_event_sent:
                 #check for spurious control and undo it
                 last_wid, last_key_event = self.last_key_event_sent
                 if last_wid == wid and last_key_event.keyname == "Control_L" and last_key_event.pressed == True:
                     #undo it:
                     last_key_event.pressed = False
                     KeyboardBase.process_key_event(self,
                                                    send_key_action_cb,
                                                    last_wid,
                                                    last_key_event)
             self.AltGr_modifiers(key_event.modifiers,
                                  not key_event.pressed)
     if key_event.keyname == "period" and key_event.keyval == 46 and key_event.keycode == 110:
         log("patched 'period' keyname to 'KP_Decimal'")
         key_event.keyname = "KP_Decimal"
     elif key_event.keyname == "dead_tilde" and key_event.keyval == 65107 and key_event.keycode == 50:
         log("patched 'dead_tilde' keyname to 'asciitilde'")
         key_event.keyname = "asciitilde"
     elif key_event.keyname == "dead_grave" and key_event.keyval == 65104 and key_event.keycode == 55:
         log("patched 'dead_grave' keyname to 'grave'")
         key_event.keyname = "grave"
     self.last_key_event_sent = (wid, key_event)
     send_key_action_cb(wid, key_event)
Beispiel #9
0
 def process_key_event(self, send_key_action_cb, wid, key_event):
     """ Caps_Lock and Num_Lock don't work properly: they get reported more than once,
         they are reported as not pressed when the key is down, etc
         So we just ignore those and rely on the list of "modifiers" passed
         with each keypress to let the server set them for us when needed.
     """
     if key_event.keyval == 2**24 - 1 and key_event.keyname == "VoidSymbol":
         return
     #self.modifier_mappings = None       #{'control': [(37, 'Control_L'), (105, 'Control_R')], 'mod1':
     #self.modifier_keys = {}             #{"Control_L" : "control", ...}
     #self.modifier_keycodes = {}         #{"Control_R" : [105], ...}
     #self.modifier_keycodes = {"ISO_Level3_Shift": [108]}
     #we can only deal with 'Alt_R' and simulate AltGr (ISO_Level3_Shift)
     #if we have modifier_mappings
     if EMULATE_ALTGR and self.altgr_modifier and len(
             self.modifier_mappings) > 0:
         if key_event.keyname == "Control_L":
             altgr = win32api.GetKeyState(win32con.VK_RMENU) not in (0, 1)
             #AltGr is often preceded by a spurious "Control_L" event
             #delay this one a little bit so we can skip it if an "AltGr" does come through next:
             if key_event.pressed:
                 if not altgr:
                     self.delayed_event = (send_key_action_cb, wid,
                                           key_event)
                     glib.timeout_add(EMULATE_ALTGR_CONTROL_KEY_DELAY,
                                      self.send_delayed_key)
                 return
             if not key_event.pressed and altgr:
                 #unpressed: could just skip it?
                 #(but maybe the real one got pressed.. and this would get it stuck)
                 pass
         if key_event.keyname == "Alt_R":
             #cancel "Control_L" if one was due:
             self.delayed_event = None
             return
     self.send_delayed_key()
     KeyboardBase.process_key_event(self, send_key_action_cb, wid,
                                    key_event)