コード例 #1
0
def on_event(args):
    global monitor_thread_id
    global hk
    """Callback for keyboard and mouse events"""
    if isinstance(args, KeyboardEvent):
        if args.current_key == 'A' and args.event_type == 'key down' and 'Lcontrol' in args.pressed_key:
            print("Ctrl + A was pressed");

        if args.current_key == 'K' and args.event_type == 'key down':
            print("K was pressed");

        if args.current_key == 'M' and args.event_type == 'key down' and 'U' in args.pressed_key:
            hk.unhook_mouse()
            print("Unhook mouse")

        if args.current_key == 'K' and args.event_type == 'key down' and 'U' in args.pressed_key:
            hk.unhook_keyboard()
            print("Unhook keyboard")
        if args.current_key == 'T' and args.event_type == 'key down' and 'S' in args.pressed_key:
            hk.unhook_keyboard()
            print("Unhook keyboard")
            win32api.PostThreadMessage(monitor_thread_id, win32con.WM_QUIT, 0, 0);

    if isinstance(args, MouseEvent):
        if args.current_key == 'RButton' and args.event_type == 'key down':
            print ("Right button pressed")

        if args.current_key == 'WheelButton' and args.event_type == 'key down':
            print("Wheel button pressed")
コード例 #2
0
 def fie():
     try:
         time.sleep(0.1)
         pywinauto.mouse.move(coords=(623, 350))
         time.sleep(0.1)
         pywinauto.mouse.press(button='left', coords=(623, 350))
         time.sleep(0.1)
         pywinauto.mouse.release(button='left', coords=(623, 350))
         time.sleep(0.1)
         send_keys("^a")
         app.Dialog.Open.close_click()
         win32api.PostThreadMessage(main_thread_id,
                                    win32con.WM_QUIT, 0, 0)
     except:
         #track +=1
         win32api.PostThreadMessage(main_thread_id,
                                    win32con.WM_QUIT, 0, 0)
コード例 #3
0
 def fourth():
     try:
         app.Dialog.move_window(x=200, y=200)
         pywinauto.mouse.move(coords=(753, 250))
         time.sleep(0.1)
         pywinauto.mouse.press(button='left', coords=(753, 250))
         time.sleep(0.1)
         pywinauto.mouse.release(button='left', coords=(753, 250))
         time.sleep(0.1)
         send_keys("{BACKSPACE}")
         send_keys(incoming)
         send_keys("{ENTER}")
         win32api.PostThreadMessage(main_thread_id,
                                    win32con.WM_QUIT, 0, 0)
     except:
         #track +=1
         win32api.PostThreadMessage(main_thread_id,
                                    win32con.WM_QUIT, 0, 0)
コード例 #4
0
def postThreadMesssageClose(uTid):
    """ Posts a WM_CLOSE message to the specified thread."""
    fRc = False;
    try:
        win32api.PostThreadMessage(uTid, win32con.WM_CLOSE, 0, 0);                                  # pylint: disable=no-member
        fRc = True;
    except:
        reporter.logXcpt('uTid=%s' % (uTid,));
    return fRc;
コード例 #5
0
def postThreadMesssageQuit(uTid):
    """ Posts a WM_QUIT message to the specified thread."""
    fRc = False;
    try:
        win32api.PostThreadMessage(uTid, win32con.WM_QUIT, 0x40010004, 0); # DBG_TERMINATE_PROCESS  # pylint: disable=no-member
        fRc = True;
    except:
        reporter.logXcpt('uTid=%s' % (uTid,));
    return fRc;
コード例 #6
0
def postThreadMesssageClose(uTid):
    """ Posts a WM_CLOSE message to the specified thread."""
    fRc = False
    try:
        win32api.PostThreadMessage(uTid, win32con.WM_CLOSE, 0, 0)
        fRc = True
    except:
        reporter.logXcpt('uTid=%s' % (uTid, ))
    return fRc
コード例 #7
0
def QuitBot():
    global goFlag, stopFlag, th3, th2, window, th2_id
    if (stopFlag == 0):
        goFlag = 0
        stopFlag = 1
        win32api.PostThreadMessage(th2_id, win32con.WM_QUIT, 0, 0)
        th.join()
        th2.join()
    window.destroy()
    SetUserFiles()
コード例 #8
0
 def first():
     try:
         pywinauto.mouse.move(coords=(255, 233))
         time.sleep(0.1)
         pywinauto.mouse.press(button='left', coords=(255, 233))
         time.sleep(0.1)
         pywinauto.mouse.release(button='left', coords=(255, 233))
         time.sleep(0.1)
         pywinauto.mouse.move(coords=(255, 255))
         time.sleep(0.1)
         pywinauto.mouse.press(button='left', coords=(255, 255))
         time.sleep(0.1)
         pywinauto.mouse.release(button='left', coords=(255, 255))
         win32api.PostThreadMessage(main_thread_id, win32con.WM_QUIT, 0,
                                    0)
     except:
         #track +=1
         win32api.PostThreadMessage(main_thread_id, win32con.WM_QUIT, 0,
                                    0)
コード例 #9
0
def postThreadMesssageQuit(uTid):
    """ Posts a WM_QUIT message to the specified thread."""
    fRc = False
    try:
        win32api.PostThreadMessage(uTid, win32con.WM_QUIT, 0x40010004, 0)
        # DBG_TERMINATE_PROCESS
        fRc = True
    except:
        reporter.logXcpt('uTid=%s' % (uTid, ))
    return fRc
コード例 #10
0
 def sec():
     try:
         pywinauto.mouse.press(button='left', coords=(314, 633))
         time.sleep(0.1)
         pywinauto.mouse.release(button='left', coords=(314, 633))
         send_keys("^a")
         send_keys("{BACKSPACE}")
         send_keys(
             "C:{\}Users{\}ksolanki{\}Documents{\}rre"
         )  #"{\}{\}video-01{\}Operations{\}SBETs{\}LA19_LSU_Rinex_Files{\}%s" % dest)
         time.sleep(0.1)
         app.Options.Ok.close_click()
         win32api.PostThreadMessage(main_thread_id,
                                    win32con.WM_QUIT, 0, 0)
     except:
         #track +=1
         print(sys.exc_info())
         win32api.PostThreadMessage(main_thread_id,
                                    win32con.WM_QUIT, 0, 0)
コード例 #11
0
def _console_exit_handler(dwCtrlType):
    # print("_app_starter: _console_exit_handler")

    # FROM: https://docs.microsoft.com/en-gb/windows/desktop/winmsg/wm-quit
    # "Do not post the WM_QUIT message using the PostMessage function; use PostQuitMessage."
    # BUT: WM_QUIT did work, PostQuitMessage didn't, win32con.WM_DESTROY didn't either

    wParam = 1  # postQuitExitCode gets this
    lParam = 2  # not sure if used
    win32api.PostThreadMessage(mainThreadId, win32con.WM_QUIT, wParam, lParam)

    return True
コード例 #12
0
def on_timer():
    pywinauto.mouse.move(coords=(365, 173))
    time.sleep(1)
    pywinauto.mouse.press(button='left', coords=(365, 173))
    time.sleep(1)
    pywinauto.mouse.release(button='left', coords=(365, 173))
    time.sleep(1)
    pywinauto.mouse.move(coords=(365, 255))
    time.sleep(1)
    pywinauto.mouse.press(button='left', coords=(255, 255))
    time.sleep(1)
    pywinauto.mouse.release(button='left', coords=(255, 255))
    time.sleep(1)
    win32api.PostThreadMessage(main_thread_id, win32con.WM_QUIT, 0, 0)
コード例 #13
0
            def second():
                try:
                    if (app2_dlg.CheckBox.get_toggle_state() == 0):
                        app2_dlg.CheckBox.click()
                        time.sleep(0.1)
                    if (app2_dlg.CheckBox2.get_toggle_state() == 0):
                        app2_dlg.CheckBox2.click()
                        time.sleep(0.1)

                    if (app2_dlg.CheckBox9.get_toggle_state() == 0):
                        app2_dlg.CheckBox9.click()
                        time.sleep(0.1)

                    if (app2_dlg.CheckBox10.get_toggle_state() == 0):
                        app2_dlg.CheckBox10.click()
                        time.sleep(0.1)
                    app.Options.move_window(x=200, y=200)
                    pywinauto.mouse.move(coords=(314, 633))
                    win32api.PostThreadMessage(main_thread_id,
                                               win32con.WM_QUIT, 0, 0)
                except:
                    #track +=1
                    win32api.PostThreadMessage(main_thread_id,
                                               win32con.WM_QUIT, 0, 0)
コード例 #14
0
def _console_exit_handler(dwCtrlType):
    logging.debug("_console_exit_handler %s" % dwCtrlType)

    # if we get threadId from here, it's different, than main
    # print("t3", mainThreadId)

    # FROM: https://docs.microsoft.com/en-gb/windows/desktop/winmsg/wm-quit
    # "Do not post the WM_QUIT message using the PostMessage function; use PostQuitMessage."
    # BUT: WM_QUIT did work, PostQuitMessage didn't, win32con.WM_DESTROY didn't either

    wParam = 1  # postQuitExitCode gets this
    lParam = 2  # not sure if used
    logging.debug("posting WM_QUIT")
    win32api.PostThreadMessage(mainThreadId, win32con.WM_QUIT, wParam, lParam)
    # win32gui.PostThreadMessage(mainThreadId, win32con.WM_NULL, 0, 0)

    return True
コード例 #15
0
def OnKeyboardEvent(event):
    global hm
    global events
    global recording
    global starttime
    global main_thread_id
    '''
	print('MessageName:',event.MessageName)
	print('Message:',event.Message)
	print('Time:',event.Time)
	print('Window:',event.Window)
	print('WindowName:',event.WindowName)
	print('Ascii:', event.Ascii, chr(event.Ascii))
	print('Key:', event.Key)
	print('KeyID:', event.KeyID)
	print('ScanCode:', event.ScanCode)
	print('Extended:', event.Extended)
	print('Injected:', event.Injected)
	print('Alt', event.Alt)
	print('Transition', event.Transition)
	print('---')
	'''

    if (recording == True):
        if (event.Key == "End"):
            hm.UnhookKeyboard()
            hm.UnhookMouse()
            win32api.PostThreadMessage(main_thread_id, win32con.WM_QUIT, 0, 0)
            events.append(["0", "0", "1", event.Time, "0"])
            print("Ended recording")
            print('\a')
            return False
        else:
            events.append(
                [event.Extended, event.KeyID, event.Message, event.Time, "1"])

    if (recording == False):
        if (event.Key == "Home" and event.Message == 257):
            starttime = datetime.datetime.now().time()
            recording = True
            print("Started recording")
            print('\a')
            events.append(["0", "0", "0", event.Time, "0"])
            return False

    return True
コード例 #16
0
    def TerminateProcess(self, pid):
        """
        Cleanly shutdown the specified process this manager has created.

        @param pid: the id of the process to terminate.
        @type pid: string? integer?
        """
        terminated = 0
        try:
            ret = 0
            win32api.PostThreadMessage(self.threadid[pid], 18, 0, 0)
            ret = win32event.WaitForSingleObject(pid, 500)
            if ret == win32event.WAIT_OBJECT_0:
                terminated = 1
            else:
                log.warn("Couldn't terminate process %s cleanly (%s)", pid,
                         str(ret))
        except win32process.error, e:
            log.exception("couldn't shutdown process %s: %s", pid, e)
コード例 #17
0
ファイル: main.py プロジェクト: lanhao34/kancolle
 def onKeyboardEvent(self, event):
     if event.Key == 'F9':
         thread.start_new_thread(self.change_argv, ())
     if event.Key == 'F10':
         if self.suspended:
             print "Press F10 to pause."
             win32process.ResumeThread(self.handle)
             self.suspended = False
         else:
             print "Press F10 to continue."
             win32process.SuspendThread(self.handle)
             self.suspended = True
     if event.Key == 'F8':
         win32api.PostThreadMessage(win32api.GetCurrentThreadId(),
                                    win32con.WM_QUIT, 0, 0)
     if event.Key == 'F12':
         print 'killed thread'
         self.suspended = False
         terminate_thread(int(self.tid))
         self.handle, self.tid = win32process.beginthreadex(
             None, 0, self.main, (), 0)
     return True
コード例 #18
0
def stop_pumping(thread_id):
    # Posts a Quit message to the message queue
    win32api.PostThreadMessage(thread_id, win32con.WM_QUIT, 0, 0)
コード例 #19
0
def ClickMid():
    global goFlag, stopFlag, numberOfGamesFinished, gameFlag, lbl1, lbl2, lbl3, timeSinceLastClick
    SetStatus('Current status: Waiting for game to start...')
    # Wait until recall is visible, then we know we're in game
    while (not AttemptToClickOnPix(
            game_recall_coords, game_recall_color, isGame=True, click=False)):
        if (stopFlag):
            return
        if (not goFlag):
            time.sleep(1)
            continue
        time.sleep(1)
    # Lock the screen once we're in game
    LockScreen()
    # Test to see if the game just started, or if the bot started mid game (check trinket)
    if (AttemptToClickOnPix(game_trinket_coords,
                            game_trinket_color,
                            isGame=True,
                            click=False)):
        SetStatus('Current status: Waiting for minions to spawn...')
        rect = GetGameCoords()
        x = rect[0] + 1170
        y = rect[1] + 666
        win32api.SetCursorPos((x, y))
        time.sleep(15)
        win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN, x, y, 0, 0)
        win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTUP, x, y, 0, 0)
        for i in range(70):
            if (stopFlag):
                return
            time.sleep(1)
    # Click mid
    SetStatus('Current status: Running it down mid...')
    gameFlag = 1
    while (gameFlag):
        if (stopFlag):
            return
        if (not goFlag):
            time.sleep(1)
            continue
        # If we're out of game
        if (not IsLeagueInGame()):
            gameFlag = 0
            continue
        try:
            rect = GetGameCoords()
        except Exception as e:
            time.sleep(3)
            continue
        x = rect[0] + 1260
        y = rect[1] + 592
        # Right click down mid
        for i in range(5):
            if (not goFlag):
                continue
            #if(AttemptToClickOnPix(game_health_coords, game_health_color, isGame=True, click=False)):
            #FallBack()
            try:
                win32api.SetCursorPos((x, y))
                win32api.mouse_event(win32con.MOUSEEVENTF_MIDDLEDOWN, x, y, 0,
                                     0)
                win32api.mouse_event(win32con.MOUSEEVENTF_MIDDLEUP, x, y, 0, 0)
                time.sleep(1)
            except Exception:
                time.sleep(3)
                continue
    if (not stopFlag):
        IncrementGames()
        if (numberOfGamesFinished == numberOfGamesToPlay):
            SetStatus("The bot successfully finished %d out of %d games!" %
                      (numberOfGamesFinished, numberOfGamesToPlay))
            lbl3.config(text="")
            lbl2.config(text="")
            stopFlag = 1
            win32api.PostThreadMessage(th2_id, win32con.WM_QUIT, 0, 0)
            return
        SetStatus("Currently queueing for a game...")
        timeSinceLastClick = timer()
        while (not AttemptToClickOnPix(skip_honor_coords, skip_honor_color)):
            if (stopFlag):
                return
            if (DidTimeout(30)):
                ClientStuck()
                return
            time.sleep(1)
コード例 #20
0
ファイル: pywatcher.py プロジェクト: jorge4larcon/pywatcher
 def stop():
     STOP_EVENT.wait()
     win32api.PostThreadMessage(thread_id, win32con.WM_QUIT, 0, 0)
コード例 #21
0
def stop():
    if listener_thread_id is not None:
        win32api.PostThreadMessage(listener_thread_id, win32con.WM_QUIT, 0, 0)
コード例 #22
0
ファイル: new keylogger.py プロジェクト: Arunsai/KeyLogger
def stopKeylog():
    win32api.PostThreadMessage(main_thread_id, win32con.WM_QUIT, 0, 0)
コード例 #23
0
ファイル: demo.py プロジェクト: EasonBlack/Python-Study
 def on_timer():
     win32api.PostThreadMessage(main_thread_id, win32con.WM_QUIT, 0, 0)
コード例 #24
0
def on_timer():
    """Callback by timer out"""
    win32api.PostThreadMessage(main_thread_id, win32con.WM_QUIT, 0, 0)
コード例 #25
0
def start():
    '''Creates and runs the application

    This function initializes a QApplication instance, sets up
    the threads needed for it to operate and runs them untill
    an application exit is registered, when all the processes
    are terminated.
    '''
    parsedConfig = config.parse()

    # Create the application
    app = QApplication(sys.argv)

    # App settings
    app.setQuitOnLastWindowClosed(False)
    app.setWindowIcon(QIcon("icon.png"))

    # Create all pieces of the UI
    mainUI = Main(parsedConfig)
    pasteUI = Paste(parsedConfig)

    QApplication.instance().installEventFilter(pasteUI)

    mainUI.show()

    ######################
    # Register the custom clipboard format used for recognizing
    # internal clipboard changes
    clipboard.registerCustomClipboardFormat()

    ######################
    # Defining the functions that are being ran on pressing
    # and releasing the hotkey combination

    def pastePress():
        t = QThread.currentThread()
        getattr(t, "showPaste").emit(clipboard.getHistory())
        setattr(t, "foregroundWindow", win32gui.GetForegroundWindow())

    def pasteRelease():
        t = QThread.currentThread()
        getattr(t, "hidePaste").emit()
        win32gui.SetForegroundWindow(getattr(t, "foregroundWindow"))
        hotkey.sendPasteMessage()

    ######################
    # Create the two threads we need:
    #   1 - Monitoring thread
    #       Polls the clipboard for changes
    #   2 - Paste thread
    #       Listens for the Ctrl + V hotkey and handles the
    #       paste mechanism.
    clipboardMonitorThread = QThread()
    clipboardMonitorThread.run = clipboard.monitorClipboard
    clipboardMonitorThread.config = parsedConfig
    clipboardMonitorThread.start()

    pasteThread = QThread()
    pasteThread.run = partial(hotkey.listenForPaste, pastePress, pasteRelease)
    pasteThread.showPaste = pasteUI.showPaste
    pasteThread.hidePaste = pasteUI.hidePaste
    pasteThread.config = parsedConfig
    pasteThread.start()

    #######################
    # Handle updating the preferences in all threads, so
    # changes can be reflected on pressing the "Save"
    # (preferences) button

    def updateConfig():
        parsedConfig = config.parse()
        pasteUI.initConfig(parsedConfig)
        clipboardMonitorThread.config = parsedConfig
        pasteThread.config = parsedConfig

    # Connect the update function to the update signal
    mainUI.updatePreferences.connect(updateConfig)

    #########################
    # Run the app
    app.exec_()

    # Once we exit we need to take care of the threads
    #
    # Set do_run to false as it's being checked against
    # in the while loop, so it causes it to break
    clipboardMonitorThread.do_run = False

    # Send the WM_QUIT message to the paste thread which
    # is being listened for in the while loop and it's
    # causing it to break
    win32api.PostThreadMessage(getattr(pasteThread, "threadId"),
                               win32con.WM_QUIT, 0, 0)

    # Join the threads in the main one to make sure they
    # are completely terminated
    clipboardMonitorThread.wait()
    pasteThread.wait()

    # Exit
    sys.exit()
コード例 #26
0
 def destroy(self):
     self.keyThreadId = win32api.GetCurrentThreadId()
     win32api.PostThreadMessage(self.keyThreadId, win32con.WM_DESTROY, 0, 0);
コード例 #27
0
ファイル: status.py プロジェクト: beiske/play
 def Close(self):
     assert self.threadid, "No thread!"
     win32api.PostThreadMessage(self.threadid, win32con.WM_QUIT, 0, 0)
コード例 #28
0
 def cancel(self):
     if self.is_alive():
         self.hm.UnhookKeyboard()
         win32api.PostThreadMessage(self.ident, win32con.WM_QUIT)
コード例 #29
0
ファイル: monitor.py プロジェクト: greyenergy/FX_Mouse
def shutdown_monitor():
    global end_proc
    win32api.PostThreadMessage(main_thread_id, win32con.WM_QUIT, 0, 0)
    end_proc = True
    exit()
コード例 #30
0
def stop():
    if(listenerThreadID is not None):
        win32api.PostThreadMessage(listenerThreadID, win32con.WM_QUIT, 0, 0)