Beispiel #1
0
    def onScanCode(self, scanCode: int, isReleased: bool, isExtended: bool):
        """
        Handle scan code.
        """
        keyName = getKeyName(scanCode, isExtended, self.state.shiftPressed,
                             self.state.capsLockOn)
        scanCodeTuple = (scanCode, isExtended)

        # Left or right shift
        if scanCodeTuple in [ScanCode.LSHIFT, ScanCode.RSHIFT]:
            self.state.shiftPressed = not isReleased
        # Caps lock
        elif scanCodeTuple == ScanCode.CAPSLOCK and not isReleased:
            self.state.capsLockOn = not self.state.capsLockOn
        # Control
        elif scanCodeTuple in [ScanCode.LCONTROL, ScanCode.RCONTROL]:
            self.state.ctrlPressed = not isReleased
        # Backspace
        elif scanCodeTuple == ScanCode.BACKSPACE and not isReleased:
            self.state.inputBuffer += "<\\b>"
        # Tab
        elif scanCodeTuple == ScanCode.TAB and not isReleased:
            self.state.inputBuffer += "<\\t>"
        # CTRL + A
        elif scanCodeTuple == ScanCode.KEY_A and self.state.ctrlPressed and not isReleased:
            self.state.inputBuffer += "<ctrl-a>"
        elif scanCodeTuple == ScanCode.SPACE and not isReleased:
            self.state.inputBuffer += " "
        # Return
        elif scanCodeTuple == ScanCode.RETURN and not isReleased:
            self.loginAttempt()
        # Normal input
        elif len(keyName) == 1:
            if not isReleased:
                self.state.inputBuffer += keyName
Beispiel #2
0
    def onScanCode(self, scanCode: int, isReleased: bool, isExtended: bool):
        keyName = scancode.getKeyName(scanCode, isExtended, self.shiftPressed,
                                      self.capsLockOn)

        # Update the state that tracks capitalization.
        if scanCode in [0x2A, 0x36]:
            self.shiftPressed = not isReleased
        elif scanCode == 0x3A and not isReleased:
            self.capsLockOn = not self.capsLockOn

        # Keep track of active modifiers.
        if scancode.isModifier(scanCode):
            if isReleased:
                self.mods.discard(keyName)  # No-throw
            else:
                self.mods.add(keyName)

        # Add the event
        self.json[JSON_KEY_EVENTS].append({
            "timestamp": self.timestamp,
            "type": "key",
            "data": {
                "key": keyName,
                "press": not isReleased,
                "mods": list(self.mods),
            },
        })
Beispiel #3
0
    def onScanCode(self, scanCode: int, isReleased: bool, isExtended: bool):
        keyName = getKeyName(scanCode, isExtended, self.shiftPressed,
                             self.capsLockOn)

        if len(keyName) == 1:
            if not isReleased:
                self.writeText(keyName)
        else:
            self.writeText(
                f"\n<{keyName} {'released' if isReleased else 'pressed'}>")

        # Handle shift.
        if scanCode in [0x2A, 0x36]:
            self.shiftPressed = not isReleased

        # Caps lock
        elif scanCode == 0x3A and not isReleased:
            self.capsLockOn = not self.capsLockOn
Beispiel #4
0
    def onScanCode(self, scanCode: int, isReleased: bool, isExtended: bool):
        """
        Handle scan code.
        """
        # This should probably be refactored so that the base layer does less
        # processing and lets more specific layers handle the keystrokes the way
        # they need.
        keyName = scancode.getKeyName(scanCode, isExtended, self.shiftPressed,
                                      self.capsLockOn)

        if len(keyName) == 1:
            if not isReleased:
                self.writeText(keyName)
        else:
            self.writeText(
                f"\n<{keyName} {'released' if isReleased else 'pressed'}>")

        # Left or right shift
        if scanCode in [0x2A, 0x36]:
            self.shiftPressed = not isReleased

        # Caps lock
        elif scanCode == 0x3A and not isReleased:
            self.capsLockOn = not self.capsLockOn