def special_action(self, event): hex_key = keymap.convert(ecodes.KEY[event.code]) if event.value == 0: self.action = [] else: self.action.append(hex_key) self.action.sort() if cmp(self.action, self.action1) == 0: print("research") pid = self.getServicePID() if pid is not None: os.system("kill -9 " + pid) os.system("sh " + Keyboard.KEYBOARD_HOME + "/start.sh -s &") os.system("kill -9 " + str(os.getpid())) elif cmp(self.action, self.action2) == 0: print("next") nextmac = self.getNext() print(nextmac) pid = self.getServicePID() if pid is not None: os.system("kill -9 " + pid) if nextmac is not None: os.system("sh " + Keyboard.KEYBOARD_HOME + "/start.sh -n " + self.getNext() + " &") else: os.system("sh " + Keyboard.KEYBOARD_HOME + "/start.sh -d &") os.system("kill -9 " + str(os.getpid()))
def change_state(self, event): evdev_code = ecodes.KEY[event.code] modkey_element = keymap.modkey(evdev_code) if modkey_element > 0: if self.mods[modkey_element] == 0: self.mods[modkey_element] = 1 else: self.mods[modkey_element] = 0 self.lock = mapneo.locks(self.mods, self.lock) else: #Get the keycode of the key hex_key_old = keymap.convert(ecodes.KEY[event.code]) hex_key = mapneo.convert(hex_key_old, self.mods, self.state[2], self.lock) #Loop through elements 4 to 9 of the inport report structure for i in range(4, 10): #(4,10) if self.state[i] == hex_key and event.value == 0: #Code 0 so we need to depress it self.state[i] = 0x00 elif self.state[i] == 0x00 and event.value == 1: #if the current space if empty and the key is being pressed self.state[i] = hex_key break
def change_state(self, button, event, i): inputStr = database.keyDatabase(button.objectName(), i) if inputStr == 'ctrl' or inputStr == 'shift' or inputStr == 'alt': inputStr = 'left' + inputStr elif inputStr == 'caps': inputStr = inputStr + 'lock' elif inputStr == '.': inputStr = 'dot' evdev_code = "KEY_" + inputStr.upper() modkey_element = keymap.modkey(evdev_code) if modkey_element > 0: if self.state[2][modkey_element] == 0: self.state[2][modkey_element] = 1 else: self.state[2][modkey_element] = 0 else: #Get the keycode of the key #hex_key = keymap.convert(ecodes.KEY[event.code]) hex_key = keymap.convert(evdev_code) #Loop through elements 4 to 9 of the inport report structure for i in range(4, 10): if self.state[i] == hex_key and event == 0: #Code 0 so we need to depress it self.state[i] = 0x00 elif self.state[i] == 0x00 and event == 1: #if the current space if empty and the key is being pressed self.state[i] = hex_key break
def update(self, event): code = evdev.ecodes.KEY[event.code] modkey = keymap.modkey(code) if modkey > 0: self.modifier_state ^= 1 << (7 - modkey) else: key = keymap.convert(code) for i in range(len(self.key_state)): if self.key_state[i] == 0 and event.value == 1: self.key_state[i] = key break elif self.key_state[i] == key and event.value == 0: self.key_state[i] = 0
def event_loop(self): """ Loop to check for keyboard events and send HID message over D-Bus keyboard service when they happen """ print('Listening...') for event in self.dev.read_loop(): # only bother if we hit a key and its an up or down event if event.type == evdev.ecodes.EV_KEY and event.value < 2: key_str = evdev.ecodes.KEY[event.code] mod_key = keymap.modkey(key_str) if mod_key > -1: self.update_mod_keys(mod_key, event.value) else: self.update_keys(keymap.convert(key_str), event.value) self.send_keys()
def change_state(self, event): evdev_code = ecodes.KEY[event.code] modkey_element = keymap.modkey(evdev_code) if modkey_element > 0: if self.state[2][modkey_element] == 0: self.state[2][modkey_element] = 1 else: self.state[2][modkey_element] = 0 else: hex_key = keymap.convert(evdev_code) for i in range(4, 10): if self.state[i] == hex_key and event.value == 0: self.state[i] = 0x00 elif self.state[i] == 0x00 and event.value == 1: self.state[i] = hex_key break
def change_state(self,event): evdev_code = ecodes.KEY[event.code] modkey_element = keymap.modkey(evdev_code) if modkey_element > 0: if self.state[2][modkey_element] == 0: self.state[2][modkey_element] = 1 else: self.state[2][modkey_element] = 0 else: hex_key = keymap.convert(evdev_code) for i in range(4,10): if self.state[i] == hex_key and event.value == 0: self.state[i] = 0x00 elif self.state[i] == 0x00 and event.value == 1: self.state[i] = hex_key break
def change_state(self, event): evdev_code = ecodes.KEY[event.code] modkey_element = keymap.modkey(evdev_code) if modkey_element > 0: # Need to set one of the modifier bits if self.state[2][modkey_element] == 0: self.state[2][modkey_element] = 1 else: self.state[2][modkey_element] = 0 else: # Get the hex keycode of the key hex_key = keymap.convert(ecodes.KEY[event.code]) # Loop through elements 4 to 9 of the input report structure for i in range (4, 10): if self.state[i] == hex_key and event.value == 0: # Code is 0 so we need to depress it self.state[i] = 0x00 elif self.state[i] == 0x00 and event.value == 1: # If the current space is empty and the key is being pressed self.state[i] = hex_key break
def getReport(self, json): # The structure for an bt keyboard input report (size is 10 bytes) report = [ 0xA1, # This is an input report 0x01, # Report ID # Bit array for Modifier keys [0, # Right GUI - (usually the Windows key) 0, # Right ALT 0, # Right Shift 0, # Right Control 0, # Left GUI - (again, usually the Windows key) 0, # Left ALT 0, # Left Shift 0], # Left Control 0x00, # Vendor reserved 0x00, # Rest is space for 6 keys 0x00, 0x00, 0x00, 0x00, 0x00 ] # Expects json to be in the form of {"pressedKeys": ["KEY_LEFTSHIFT", "KEY_A"]} if 'pressedKeys' not in json.keys(): return pressedKeys = json['pressedKeys'] startIndexForKeys = 4 for pressedKey in pressedKeys: modkey_element = keymap.modkey(pressedKey) if modkey_element > 0: report[2][modkey_element] = 1 else: # Get the hex keycode of the key hex_key = keymap.convert(pressedKey) report[startIndexForKeys] = hex_key startIndexForKeys += 1 return report
def change_state(self, event): # linux and X codes differ by X's reserved 8? evdev_code = ecodes.KEY[event.detail - 8] modkey_element = keymap.modkey(evdev_code) if modkey_element > 0: # Need to set one of the modifier bits if self.state[2][modkey_element] == 0: self.state[2][modkey_element] = 1 else: self.state[2][modkey_element] = 0 else: # Get the hex keycode of the key hex_key = keymap.convert(evdev_code) # Loop through elements 4 to 9 of the input report structure for i in range(4, 10): if self.state[i] == hex_key and event.type == X.KeyRelease: # Code is 0 so we need to depress it self.state[i] = 0x00 break elif self.state[i] == 0x00 and event.type == X.KeyPress: # If the current space is empty and the key is being pressed self.state[i] = hex_key break
def change_keyboard_state(self, event): evdev_code = ecodes.KEY[event.code] modkey_element = keymap.modkey(evdev_code) if modkey_element > 0: if self.keyboard_state[2][modkey_element] == 0: self.keyboard_state[2][modkey_element] = 1 else: self.keyboard_state[2][modkey_element] = 0 else: # Get the keycode of the key hex_key = keymap.convert(ecodes.KEY[event.code]) print("Key " + str(ecodes.KEY[event.code]) + " was pressed") # Loop through elements 4 to 9 of the input report structure for i in range(4, 10): if self.keyboard_state[i] == hex_key and event.value == 0: # Code 0 so we need to depress it self.keyboard_state[i] = 0x00 elif self.keyboard_state[i] == 0x00 and event.value == 1: # if the current space is empty and the key is being pressed self.keyboard_state[i] = hex_key break