def control_eclipse(message):
    pythoncom.CoInitialize()

    if "query" in message or "search" in message:
        shell = win32com.client.Dispatch("WScript.Shell")
        shell.AppActivate("Eclipse")
        win32api.Sleep(5000)
        shell.SendKeys("^h" + message.split("search ", 1)[1] + "~")
    elif "run" in message:
        shell = win32com.client.Dispatch("WScript.Shell")
        shell.AppActivate("Eclipse")
        win32api.Sleep(5000)
        shell.SendKeys("^{F11}")
    elif "debug" in message:
        shell = win32com.client.Dispatch("WScript.Shell")
        shell.AppActivate("Eclipse")
        win32api.Sleep(5000)
        shell.SendKeys("{F11}")
    elif "indent" in message:
        shell = win32com.client.Dispatch("WScript.Shell")
        shell.AppActivate("Eclipse")
        win32api.Sleep(5000)
        shell.SendKeys("^a^i")
    elif "coverage" in message:
        shell = win32com.client.Dispatch("WScript.Shell")
        shell.AppActivate("Eclipse")
        win32api.Sleep(5000)
        shell.SendKeys("^+{F11}")
Example #2
0
def enter_keys(hwnd, password):
    win32gui.SetForegroundWindow(hwnd)
    win32api.Sleep(100)

    for c in password:
        win32api.SendMessage(hwnd, win32con.WM_CHAR, ord(c), 0)
        win32api.Sleep(100)
def control_intelliJ(message):
    pythoncom.CoInitialize()

    if "query" in message or "search" in message:
        shell = win32com.client.Dispatch("WScript.Shell")
        shell.AppActivate("IntelliJ IDEA")
        win32api.Sleep(5000)
        shell.SendKeys("^+f" + message.split("search ", 1)[1])
    elif "build" in message:
        shell = win32com.client.Dispatch("WScript.Shell")
        shell.AppActivate("IntelliJ IDEA")
        win32api.Sleep(5000)
        shell.SendKeys("^{F9}")
    elif "run" in message:
        shell = win32com.client.Dispatch("WScript.Shell")
        shell.AppActivate("IntelliJ IDEA")
        win32api.Sleep(5000)
        shell.SendKeys("+{F10}")
    elif "debug" in message:
        shell = win32com.client.Dispatch("WScript.Shell")
        shell.AppActivate("IntelliJ IDEA")
        win32api.Sleep(5000)
        shell.SendKeys("+{F9}")
    elif "indent" in message:
        shell = win32com.client.Dispatch("WScript.Shell")
        shell.AppActivate("IntelliJ IDEA")
        win32api.Sleep(5000)
        shell.SendKeys("^%l")
Example #4
0
 def sentries_alert(url, sentries, username, password):
     """put each sentry on alert according to their schedules"""
     try:
         last_run = {}
         first_run = 1
         i = 1
         while i > 0:
             for sentry in sentries["sentries"]:
                 if first_run == 1 or last_run[
                         sentry["id"]] < datetime.datetime.now(
                         ) - datetime.timedelta(
                             0, 0, 0, 0, sentry["survey_interval"], 0, 0):
                     result = run_module(sentry["module"],
                                         sentry["parameters"])
                     last_run[sentry["id"]] = datetime.datetime.now()
                     data = "type=Sentry&data=%s" % (result)
                     event_url = "%s/sentries/%s/events" % (url,
                                                            sentry["id"])
                     print http_post(event_url, username, password, data)
                     print "sentry #%s was last run at %s" % (
                         sentry["id"], last_run[sentry["id"]])
             first_run = 0
             win32api.Sleep(60)
     except:
         win32api.Sleep(60)
Example #5
0
    def process(self, frame, out):
        RWRIST = 4
        LWRIST = 7

        _, rWristConf, _, rWristPoint = cv.minMaxLoc(out[0, RWRIST, :, :])
        _, lWristConf, _, lWristPoint = cv.minMaxLoc(out[0, LWRIST, :, :])

        if abs(rWristPoint[0] - lWristPoint[0]) <= 2 and \
           abs(rWristPoint[1] - lWristPoint[1]) <= 2:
            if lWristConf > rWristConf:
                out[0, RWRIST, rWristPoint[1] - 2:rWristPoint[1] + 3,
                    rWristPoint[0] - 2:rWristPoint[0] + 3] = 0
                _, rWristConf, _, rWristPoint = cv.minMaxLoc(out[0,
                                                                 RWRIST, :, :])
            else:
                out[0, LWRIST, lWristPoint[1] - 2:lWristPoint[1] + 3,
                    lWristPoint[0] - 2:lWristPoint[0] + 3] = 0
                _, lWristConf, _, lWristPoint = cv.minMaxLoc(out[0,
                                                                 LWRIST, :, :])

        colors = [(0, 255, 0), (0, 0, 255)]
        points = [rWristPoint, lWristPoint]
        confidences = [rWristConf, lWristConf]
        for i in range(2):
            point = points[i]
            color = colors[i]
            conf = confidences[i]
            x = (frame.shape[1] * point[0]) / out.shape[3]
            y = (frame.shape[0] * point[1]) / out.shape[2]
            if conf > 0.1:
                cv.circle(frame, (x, y), 5, color, cv.FILLED)
            if i == 0:
                self.rWristHistory.append(point[0] if conf > 0.1 else None)
            else:
                self.lWristHistory.append(point[0] if conf > 0.1 else None)

        if len(self.rWristHistory) == 31:
            del self.rWristHistory[0]
            if self.isSwipe(self.rWristHistory, 'left'):
                win32api.keybd_event(win32con.VK_RIGHT, 0,
                                     win32con.KEYEVENTF_EXTENDEDKEY, 0)  #press
                win32api.Sleep(50)
                win32api.keybd_event(win32con.VK_RIGHT, 0,
                                     win32con.KEYEVENTF_EXTENDEDKEY
                                     | win32con.KEYEVENTF_KEYUP, 0)  #release
                self.rWristHistory = []
                print 'left'

        if len(self.lWristHistory) == 31:
            del self.lWristHistory[0]
            if self.isSwipe(self.lWristHistory, 'right'):
                win32api.keybd_event(win32con.VK_LEFT, 0,
                                     win32con.KEYEVENTF_EXTENDEDKEY, 0)  #press
                win32api.Sleep(50)
                win32api.keybd_event(win32con.VK_LEFT, 0,
                                     win32con.KEYEVENTF_EXTENDEDKEY
                                     | win32con.KEYEVENTF_KEYUP, 0)  #release
                self.lWristHistory = []
                print 'right'
    def shortcut_keys(self, list_key=[], time=5):

        for x in list_key:
            tmp = self.dic_keycode(x)
            win32api.keybd_event(tmp, 0, 0, 0)
            win32api.Sleep(time)
        for x in list_key:
            tmp = self.dic_keycode(x)
            win32api.keybd_event(tmp, 0, win32con.KEYEVENTF_KEYUP, 0)
            win32api.Sleep(time)
        return True
Example #7
0
def createNotepad(index):
    #创建单个进程
    hlnstance = win32api.ShellExecute(0,'open',' F:\\路径.exe',",",1)
#创建速度不能太快,否则系统响应不及,就出错了
    if index<1000:
        win32api.Sleep(50)
    else:
        win32api.Sleep(100)

    hWnd = win32gui.GetForegroundWinodw()
    return hWnd
def TestExplorer(iexplore):
    if not iexplore.Visible: iexplore.Visible = -1
    iexplore.Navigate(win32api.GetFullPathName('..\\readme.htm'))
    win32api.Sleep(1000)
    TestObjectFromWindow()
    win32api.Sleep(3000)
    try:
        iexplore.Quit()
    except (AttributeError, pythoncom.com_error):
        # User got sick of waiting :)
        pass
Example #9
0
 def classic_submit(self):
   try: 
       driver = comclt.GetActiveObject("SAS.Application")
   except:
       send_alert("No SAS program opening!")
   logging.info("Submitting to sas classic ... ...")
   driver = comclt.Dispatch("Wscript.Shell")
   driver.AppActivate("SAS")
   win32api.Sleep(500)
   driver.SendKeys("{F6}")
   win32api.Sleep(500)
   driver.SendKeys("{F1}")
 def __call__(self):
     shell = win32com.client.Dispatch("WScript.Shell")
     win32api.Sleep(100)
     if self.plugin.bSpotifyObjectCreated:
         shell.AppActivate("Spotify")
         win32api.Sleep(100)
         shell.SendKeys("%")
         win32api.Sleep(500)
         shell.SendKeys("x")
     self.plugin.bTerminated = True
     del shell
     return
    def close_waveApps(self):
        #get the handle of waveApps window.
        try:
            hwnd6 = win32gui.FindWindow(WAVEApps_CLASS, None)
            print 'hwnd6:', hwnd6
            time.sleep(1)

            #set the waveApps window to the top.
            win32gui.SetForegroundWindow(hwnd6)
            time.sleep(1)
        except:
            print 'close error'
            log_public(ERR_NO_0009)
            self.m_ERROR_MSG = ERR_NO_0009
            return False

        #click the title bar.
        #self.myobj.Mouse_LB_D(str_app = WAVEApps_CLASS,lb_dx = '75',lb_dy = '10',Flag = '1')

        #send Alt+F to open 'File' in menu bar.
        win32api.Sleep(1000)
        win32api.keybd_event(18, 0, 0, 0)
        #18��Alt�ļ���
        win32api.keybd_event(70, 0, 0, 0)
        #70��F�ļ���
        win32api.Sleep(1000)
        win32api.keybd_event(70, 0, win32con.KEYEVENTF_KEYUP, 0)
        win32api.keybd_event(18, 0, win32con.KEYEVENTF_KEYUP, 0)
        win32api.Sleep(1000)

        #send X to close waveApps window.
        win32api.keybd_event(88, 0, 0, 0)
        #88��X�ļ���
        win32api.Sleep(1000)
        win32api.keybd_event(88, 0, win32con.KEYEVENTF_KEYUP, 0)
        win32api.Sleep(1000)

        if self.timeout == 1:
            #send Alt+Y to exit waveApps without save.
            win32api.keybd_event(18, 0, 0, 0)
            #18��Alt�ļ���
            win32api.keybd_event(89, 0, 0, 0)
            #89��Y�ļ���
            win32api.Sleep(1000)
            win32api.keybd_event(89, 0, win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(18, 0, win32con.KEYEVENTF_KEYUP, 0)
            win32api.Sleep(1000)
        else:
            #send Alt+N to exit waveApps without save.
            win32api.keybd_event(18, 0, 0, 0)
            #18��Alt�ļ���
            win32api.keybd_event(78, 0, 0, 0)
            #78��N�ļ���
            win32api.Sleep(1000)
            win32api.keybd_event(78, 0, win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(18, 0, win32con.KEYEVENTF_KEYUP, 0)
            win32api.Sleep(1000)
        return True
Example #12
0
def TestExplorer(iexplore):
    if not iexplore.Visible:
        iexplore.Visible = -1
    filename = os.path.join(os.path.dirname(__file__), "..\\readme.html")
    iexplore.Navigate(win32api.GetFullPathName(filename))
    win32api.Sleep(1000)
    TestObjectFromWindow()
    win32api.Sleep(3000)
    try:
        iexplore.Quit()
    except (AttributeError, pythoncom.com_error):
        # User got sick of waiting :)
        pass
Example #13
0
 def window_Mouse(dm, Doxy, nSec):
     if (Doxy != None):
         print(Doxy)
         Idox = Doxy[0]
         Idoy = Doxy[1]
         if (Idox < 400 and Idoy > 600):
             print("识别有误")
             return
         dm.MoveTo(int(Idox), int(Idoy))
         i = dm.LeftDown()
         win32api.Sleep(nSec)
         j = dm.leftUp()
         win32api.Sleep(1000)
Example #14
0
    def _input_left_mouse(self, x, y):
        left, top, right, bottom = self.rect
        width, height = right - left, bottom - top
        if x < 0 or x > width or y < 0 or y > height:
            return

        win32gui.SetForegroundWindow(self.hwnd)
        pos = win32gui.GetCursorPos()
        win32api.SetCursorPos((left+x, top+y))
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0)
        win32api.Sleep(100) #ms
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0)
        win32api.Sleep(100) #ms
Example #15
0
 def calc(cls, input):
     wscript = win32com.client.Dispatch('WScript.Shell')
     wscript.run('calc')
     win32api.Sleep(500)
     win = win32gui.FindWindow(None, '小算盤')
     win32gui.SetForegroundWindow(win)
     win32api.Sleep(500)
     for i in input:
         if i != ' ' or i != '=':
             pyautogui.press(i)
     pyautogui.press('=')
     win32api.Sleep(cls.wait_time)
     win32gui.PostMessage(win, win32con.WM_CLOSE, 0, 0)
Example #16
0
def createNotepad(index):
    # 创建单个进程
    hInstance = win32api.ShellExecute(0, 'open', 'vbpad.exe', '', '', 1)

    # 创建速度不能太快,否则系统响应不及,就出错了
    # 当然这取决于你机器的配置,很好的配置可以把参数调小些
    # 我这个是9600K + 16G内存 + SSD
    if index < 1000:
        win32api.Sleep(100)
    else:
        win32api.Sleep(250)

    hWnd = win32gui.GetForegroundWindow()
    return hWnd
Example #17
0
def DoDemoWork():
    print("Doing the work...")
    print("About to connect")
    win32api.MessageBeep(win32con.MB_ICONASTERISK)
    win32api.Sleep(2000)
    print("Doing something else...")
    win32api.MessageBeep(win32con.MB_ICONEXCLAMATION)
    win32api.Sleep(2000)
    print("More work.")
    win32api.MessageBeep(win32con.MB_ICONHAND)
    win32api.Sleep(2000)
    print("The last bit.")
    win32api.MessageBeep(win32con.MB_OK)
    win32api.Sleep(2000)
Example #18
0
 def __call__(self):
     sh = win32com.client.Dispatch("WScript.Shell")
     win32api.Sleep(100)
     if self.plugin.bSpotifyObjectCreated:
         hWnd = win32gui.FindWindow("SpotifyMainWindow", None)
         BringHwndToFront(hWnd)
         win32api.Sleep(200)
         sh.AppActivate("spotify")
         win32api.Sleep(100)
         sh.SendKeys("{UP}")
         win32api.Sleep(10)
         sh.SendKeys("~~~~")
         del hWnd
     del sh
     return
Example #19
0
def sendKeyStrokes(keystroke_string):
    ''' This will try to send keystrokes to the debugees '''
    global pids
    try:
        pythoncom.CoInitializeEx(pythoncom.COINIT_MULTITHREADED)
        shell = win32com.client.Dispatch("WScript.Shell")
        print "trying to send keys to pids:%s" % pids
        for pid in pids:
            if shell.AppActivate(pid):
                print "Keys(%s) sent to pid: %d" % (keystroke_string, pid)
                win32api.Sleep(100)
                win32api.Sleep(100)
        shell.SendKeys(keystroke_string)
    except Exception, E:
        print E
Example #20
0
    def run(self):
        """ Play the next action in the instruction list """

        # Reached the end of the instruction list
        if (self.step > (len(self.instructions) - 1)):
            if (self.cycles > 0):
                self.cycles = self.cycles - 1
                self.reset(0)
            else:
                self.stop()
                return

        action = self.instructions[self.step]

        # Delay, then do the action
        for i in range(int(action.repeat) + 1):
            self.tree.select(self.step)
            win32api.Sleep(int(action.delay))
            if self.playing:
                if not action.play():
                    self.play()
            else:
                return

        # Move to the next instruction
        self.step = self.step + 1
        if self.playing:
            self.run()
Example #21
0
def main():  #main function
    win32api.Sleep(100)  #Wait for 100 ms
    ser = serial.Serial(port='\\.\COM2',
                        baudrate=9600,
                        bytesize=serial.EIGHTBITS,
                        parity=serial.PARITY_NONE,
                        stopbits=serial.STOPBITS_ONE,
                        timeout=1)  #Serial object
    ser.isOpen()  #Wait for serial port opening with the configuration above
    accr = ''
    strh = ''
    #Initialize String for Storing Accelerometer and Stretch Sensor Reading
    time.sleep(5)  #now open the angry game within 5 sec or more
    while (1):  #Game loop
        if (ser.inWaiting() > 0
            ):  #Wait for serial port to refresh and next read to takes place
            c = ser.read(1)  #Read a single char from buffer
            if (c == 'b'):  #If the character is 'b' then get ready begin
                print 'begin'  #print begin in commmand window
                click_and_drag(
                    375, 400
                )  #click and drag the bird at (375,400) pixel of the screen
                click_and_drag(375, 400)
                click_and_drag(375, 400)
            elif (
                    c == 'a'
            ):  #If the character is 'a' then next four characters represent reading of accelerometer
                accr = ser.read(
                    4)  #Store the four byte reading of accelerometer
            elif (
                    c == 's'
            ):  #If the character is 'a' then next four characters represent reading of strech sensor
                strh = ser.read(
                    4)  #Store the four byte reading of strech sensor
            elif (
                    c == 'e'
            ):  #If the character is 'e' then get ready to release the bird
                print 'end'  #print end in commmand window
                click(x, y)  #Release the bird now at (x,y)
        if (accr != '' and
                strh != ''):  #if both values succesfully read then go inside
            a = int(accr)
            s = int(strh)
            #Convert the four byte characters to integers
            ma = min(ma, a)
            ms = min(mb, b)
            Ma = max(Ma, a)
            Ms = max(Mb, b)
            theta = (m - Ma
                     )  #Using y=mx+c to get theta from accelerometer reading
            r = (m - Ms
                 )  #Using y=mx+c to get radius from sterch sensor reading
            x = int(371 + r * math.sin(theta)
                    )  #Using x=a+b*cos(theta) parametric cooridates of circle
            y = int(411 + r * math.cos(theta)
                    )  #Using x=a+b*cos(theta) parametric cooridates of circle
            click_and_drag(x, y)  #Click and drag for every new reading
            print r, theta  #Print the reading for r and theta
            accr = ''
            strh = ''  #Reset the readings of strech sensor and accelerometer
Example #22
0
    def is_dead(self):

        r = []
        for i in range(4):
            r.append(self.get_remainging_time())
            win32api.Sleep(1100)
        return all(x == r[0] for x in r[1:])
Example #23
0
def click(x, y):
    h_x, h_y = win32api.GetCursorPos()  #Get position
    win32api.SetCursorPos((x, y))
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, x, y, 0, 0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, x, y, 0, 0)
    win32api.Sleep(500)
    win32api.SetCursorPos((h_x, h_y))  # go back to previous position
 def enter_event(self):
     win32api.keybd_event(VK_CODE['enter'], 0,
                          win32con.KEYEVENTF_EXTENDEDKEY, 0)  #press
     win32api.Sleep(50)
     win32api.keybd_event(
         VK_CODE['enter'], 0,
         win32con.KEYEVENTF_EXTENDEDKEY | win32con.KEYEVENTF_KEYUP, 0)
Example #25
0
def TestAll():
    try:
        try:
            iexplore = win32com.client.dynamic.Dispatch(
                "InternetExplorer.Application")
            TestExplorer(iexplore)

            win32api.Sleep(1000)
            iexplore = None

            # Test IE events.
            TestExplorerEvents()
            # Give IE a chance to shutdown, else it can get upset on fast
            # machines.
            time.sleep(2)

            # Note that the TextExplorerEvents will force makepy - hence
            # this gencache is really no longer needed.

            from win32com.client import gencache
            gencache.EnsureModule("{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}", 0,
                                  1, 1)
            iexplore = win32com.client.Dispatch("InternetExplorer.Application")
            TestExplorer(iexplore)
        except pythoncom.com_error as exc:
            if exc.hresult != winerror.RPC_E_DISCONNECTED:  # user closed the app!
                raise
    finally:
        iexplore = None
Example #26
0
def main():
    start = False
    words = codecs.open("words.txt").readlines()

    n = 0
    if len(sys.argv) > 1:
        n = int(sys.argv[1])
        words = words[n:]

    for i in range(len(words)):
        if not start:
            print "開始するにはEnterを押してください"
            raw_input()
            start = True
            count_down(5)

        w = words[i].replace("\n", "").replace("\r", "")
        print i + n, w, "を入力"

        CB.OpenClipboard()
        CB.EmptyClipboard()
        CB.SetClipboardText(w, CB.CF_UNICODETEXT)
        CB.CloseClipboard()
        shell.SendKeys('^v')
        win32api.Sleep(100)
        shell.SendKeys('~')
        time.sleep(1)
Example #27
0
    def move(self, x, y):
        nx = int(x * 65535 / self.x_res)
        ny = int(y * 65535 / self.y_res)

        win32api.mouse_event(
            win32con.MOUSEEVENTF_ABSOLUTE | win32con.MOUSEEVENTF_MOVE, nx, ny)
        win32api.Sleep(200)
Example #28
0
def hotkeyReset():
    if multiInstance.get():
        print('toggle focus')
        if not str(ahk.active_window.pid) == str(mcActualPid):
            print(getMcWin().pid)
            getMcWin().activate()
            return
    win = getMcWin()

    currentWorld = getMostRecentFile(savesPath.get() + "/*")
    if currentWorld == False:
        print('No world found')
        return
    win32api.keybd_event(0x84, 0)
    win32api.Sleep(3)
    win32api.keybd_event(0x84, 0, win32con.KEYEVENTF_KEYUP)
    if windowed.get() and win.active:
        print('unfocus')
        root.focus_force()
        time.sleep(0.01)
    try:
        lockFile = open(currentWorld + "/session.lock", "r")
        # fails with error 13 (permission denied) if world is running
        lockFile.read()
        makeWorld()
    except IOError as e:
        if e.args[0] == 13:
            resetRun()
        else:
            print(
                'Some generic error happened when checking world hotkey reset idk '
                + e.args[1])
Example #29
0
	def wait(self,seconds=1,message=None):
		"""pause Windows for ? seconds and print
an optional message """
		win32api.Sleep(seconds*1000)
		if message is not None:
			win32api.keybd_event(message, 0,0,0)
			time.sleep(.05)
			win32api.keybd_event(message,0 ,win32con.KEYEVENTF_KEYUP ,0)
Example #30
0
 def notepad(cls, input, saveas=None):
     wscript = win32com.client.Dispatch('WScript.Shell')
     wscript.run('notepad')
     win32api.Sleep(500)
     win = win32gui.FindWindow(None, '未命名 - 記事本')
     win32gui.SetForegroundWindow(win)
     win32api.Sleep(500)
     pyautogui.hotkey('ctrl', 'space')
     for i in input:
         pyautogui.press(i)
     win32api.Sleep(500)
     win32gui.PostMessage(win, win32con.WM_CLOSE, 0, 0)
     if saveas:
         pyautogui.hotkey('alt', 's')
         win32api.Sleep(500)
         pyautogui.write(str(saveas))
         pyautogui.hotkey('alt', 's')