def playString(keys, hooks=None):
    """do smarter and faster playString than natlink.playString
    
    If useMarkSendInput is set to 1 (True) (top of this file):
    the SendInput module of Mark Lillibridge is used.
    
    Disadvantage: does not work in elevated windows.
    
    This behaviour can be circumvented by adding a hook in the call,
    or by using SendDragonKeys, SendSystemKeys or SSK (Unimacro).
    
    If useMarkSendInput is set to 0 (False), or a hook is added
    (0x100 for normal behaviour, 0x200 for systemkeys behaviour)
    then natlink.playString is used, but a {shift} in front of the keystrokes is inserted,
    in order to prevent doubling or losing keystrokes.
    
    (if default behaviour is wanted, you can call natlink.playString directly)
    """
    if not keys:
        return
    keys = utilsqh.convertToBinary(keys)
    if hooks is None and useMarkSendInput:
        SendInput.send_input(
            ExtendedSendDragonKeys.senddragonkeys_to_events(keys))
    else:
        if hooks not in (None, 0x100):
            natlink.playString(keys, hooks)
        else:
            shiftkey = natlinkmain.shiftkey
            natlink.playString(shiftkey + keys)
Exemplo n.º 2
0
def sendkeys(keys):
    """send keystrokes to foreground window
    """
    if not keys:
        return
    SendInput.send_input(ExtendedSendDragonKeys.senddragonkeys_to_events(keys))
    pass
Exemplo n.º 3
0
def main():
    # We have to create a Window for TrackIR, but we do not need to actually
    # show it, nor run the tkinter event loop.  We set the title though just
    # in case it shows up the Windows Task Manager etc.
    app = tkinter.Tk()
    app.title("TrackIR Mouse Controller")
    app.update_idletasks()
    app.update()
    tkinter.Label(app, text="Running Mouse Controller.  Close to stop").grid(
        column=0, row=0)

    try:
        trackrIr = TrackIRDLL(app.wm_frame())
    except Exception as e:
        logprint(
            "Crash!\n  (This usually means you need to restart the trackir gui)\n"
        )
        raise e

    previous_frame = -1
    num_logged_frames = 0
    num_missed_frames = 0
    start_time = time.time()

    def signal_handler(sig, frame):
        trackrIr.stop()
        logprint("num_logged_frames:", num_logged_frames)
        logprint("num_missed_frames:", num_missed_frames)
        end_time = time.time()
        logprint("Total time:", round(end_time - start_time), "s")
        logprint("Rate:", round(num_logged_frames / (end_time - start_time)),
                 "hz")
        sys.exit(0)

    signal.signal(signal.SIGINT, signal_handler)

    print("Have fun mouse pointing!")
    while (True):
        data = trackrIr.NP_GetData()
        if data.frame != previous_frame:
            num_logged_frames += 1
            if data.frame != previous_frame + 1:
                num_missed_frames += data.frame - previous_frame - 1
            previous_frame = data.frame
            time_ms = round((time.time() - start_time) * 1000)
            logprint(data)
            SendInput.MouseMove(data.yaw, data.pitch)
        try:
            app.update_idletasks()
            app.update()
        except Exception:
            signal_handler(0, 0)
        time.sleep(1 / 240.0)  # Sample at ~240hz, for the ~120hz signal
Exemplo n.º 4
0
def wheel(amount):
    amount = int(amount)
    SendInput.send_input([mouse_wheel_event(False, amount)])
Exemplo n.º 5
0
def p(key):
    code = long(key, 16)
    SendInput.send_input(
        [Unicode_event(code, False),
         Unicode_event(code, True)])
Exemplo n.º 6
0
def send_input(specification):
    SendInput.send_input(
        ExtendedSendDragonKeys.senddragonkeys_to_events(specification))
Exemplo n.º 7
0
 def trigger_keys(self, keys):
     self.triggering = True
     SendInput.send_input(keys)
     self.triggering = False