Example #1
0
class Hotkey(object):
    def __init__(self, fire):
        self.fire = fire
        self.presscount = 0
        self.delay = 300
        self.timer_id = None

        import win32com.client
        self.shell = win32com.client.Dispatch("WScript.Shell")

        self.keyboardHook = KeyboardHook()
        self.pending = False

    def go(self):
        if self.timer_id is not None:
            timer.kill_timer(self.timer_id)
            self.timer_id = None
        if self.presscount >= 2:
            self.presscount = 0
            self.fire()
        else:
            x = self.presscount
            if x > 0:
                self.presscount = 0
                self.pending = True
                try:
                    self.shell.SendKeys(';' * x)
                finally:
                    self.pending = False

    def timer_fn(self, id, time):
        self.go()

    def kbEvent(self, nCode, wParam, lParam):
        if nCode >= 0:
            # It just occured to me that I should aso be checking for WM_SYSKEYDOWN as well
            if wParam is win32con.WM_KEYDOWN:
                if not self.pending and lParam[0] == 0xBA and not mods():
                    if self.presscount >= 0:
                        if self.timer_id is None:
                            self.timer_id = timer.set_timer(
                                self.delay, self.timer_fn)
                    self.presscount += 1
                    if self.presscount > 0:
                        # return a non-zero to prevent further processing
                        return 42
                else:
                    self.go()
        return windll.user32.CallNextHookEx(self.keyboardHook.kbHook, nCode,
                                            wParam, lParam)

    def start(self):
        pointer = getFunctionPointer(self.kbEvent)
        if not self.keyboardHook.installHook(pointer):
            raise RuntimeError('Install keyboard hook failed.')
        self.keyboardHook.keepAlive()

    def stop(self):
        self.keyboardHook.stop()
Example #2
0
class Hotkey(object):

    def __init__(self, fire):
        self.fire = fire
        self.presscount = 0
        self.delay = 300
        self.timer_id = None

        import win32com.client
        self.shell = win32com.client.Dispatch("WScript.Shell")

        self.keyboardHook = KeyboardHook()
        self.pending = False

    def go(self):
        if self.timer_id is not None:
            timer.kill_timer(self.timer_id)
            self.timer_id = None
        if self.presscount >= 2:
            self.presscount = 0
            self.fire()
        else:
            x = self.presscount
            if x > 0:
                self.presscount = 0
                self.pending = True
                try:
                    self.shell.SendKeys(';' * x)
                finally:
                    self.pending = False

    def timer_fn(self, id, time):
        self.go()

    def kbEvent(self, nCode, wParam, lParam):
        if nCode >= 0:
            # It just occured to me that I should aso be checking for WM_SYSKEYDOWN as well
            if wParam is win32con.WM_KEYDOWN:
                if not self.pending and lParam[0] == 0xBA and not mods():
                    if self.presscount >= 0:
                        if self.timer_id is None:
                            self.timer_id = timer.set_timer(self.delay, self.timer_fn)
                    self.presscount += 1
                    if self.presscount > 0:
                        # return a non-zero to prevent further processing
                        return 42
                else:
                    self.go()
        return windll.user32.CallNextHookEx(self.keyboardHook.kbHook, nCode, wParam, lParam)

    def start(self):
        pointer = getFunctionPointer(self.kbEvent)
        if not self.keyboardHook.installHook(pointer):
            raise RuntimeError('Install keyboard hook failed.')
        self.keyboardHook.keepAlive()

    def stop(self):
        self.keyboardHook.stop()
Example #3
0
    def __init__(self, fire):
        self.fire = fire
        self.presscount = 0
        self.delay = 300
        self.timer_id = None

        import win32com.client
        self.shell = win32com.client.Dispatch("WScript.Shell")

        self.keyboardHook = KeyboardHook()
        self.pending = False
Example #4
0
    def __init__(self, fire):
        self.fire = fire
        self.presscount = 0
        self.delay = 300
        self.timer_id = None

        import win32com.client
        self.shell = win32com.client.Dispatch("WScript.Shell")

        self.keyboardHook = KeyboardHook()
        self.pending = False
Example #5
0
                                       cmin=0.0,
                                       cmax=1.0,
                                       channel_axis=2).save("recording/" +
                                                            str(time.time()) +
                                                            ".png")
                    print("Intervention, " + str(time.time()))

                time.sleep(0.1)


########
# MAIN #
########

# create hooks
keyboardHook = KeyboardHook()

# create controllers
arduinoController = ArduinoController()
steeringController = SteeringController(keyboardHook)
screenCapturer = ScreenCapturer("Desktop-Win10", True)  # !!! TRUE !!!
systemManager = SystemManager(keyboardHook, steeringController, screenCapturer,
                              arduinoController)


# program exit handling
def exitHandler(keycode, character, press):
    if character == "q" and press:
        systemManager.stop()
        systemManager.join()