Exemplo n.º 1
0
    def onScanCode(self, scanCode: int, isReleased: bool, isExtended: bool):
        """
        Handle scan code.
        """
        keyName = keyboard.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>"
        # Return
        elif scanCodeTuple == ScanCode.RETURN and not isReleased:
            self.state.credentialsCandidate = self.state.inputBuffer
            self.state.inputBuffer = ""
        # Normal input
        elif len(keyName) == 1:
            if not isReleased:
                self.state.inputBuffer += keyName
Exemplo n.º 2
0
    def onScanCode(self, scanCode: int, isReleased: bool, isExtended: bool):
        """
        Handle scan code.
        """
        keyName = keyboard.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