Exemplo n.º 1
0
 def __get_text(self):
     SendKeys('^a')
     SendKeys('^c')
     win32clipboard.OpenClipboard()
     data = win32clipboard.GetClipboardData()
     win32clipboard.CloseClipboard()
     return data
Exemplo n.º 2
0
 def send_notes(self, message={}):
     """
     @note: message_dic requisite keys 'To','Cc','Title','Content'
     """
     if 'To' in message.keys():
         SendKeys("^M")
         sleep(15)
         top_dlg = self.app.top_window_()
         # print top_dlg.print_control_identifiers()
         sleep(1)
         top_dlg["Edit4"].TypeKeys(message['To'])
         if 'Cc' in message.keys():
             top_dlg["Edit3"].TypeKeys(message['Cc'])
         top_dlg["Edit0"].TypeKeys(message['Title'])
         SendKeys("{TAB}")
         SendKeys("{TAB}")
         self.writeContent(message['Content'], top_dlg)
         sleep(30)
         top_dlg['Button5'].Click()
         top_dlg['Button10'].Click()
         # print top_dlg.print_control_identifiers()
         if 'Doc' in message.keys():
             self.add_doc(message['Doc'])
         SendKeys('%A')
         sleep(2)
         SendKeys('{ENTER}')
         sleep(60)
Exemplo n.º 3
0
 def close():
     """
     @note:
     :return:
     """
     SendKeys("%F")
     sleep(1)
     SendKeys('{UP}')
     sleep(1)
     SendKeys('{ENTER}')
     sleep(1)
     SendKeys('{ENTER}')
Exemplo n.º 4
0
    def testModifiersForFewChars(self):
        "Make sure that repeated action works"
        SendKeys("%(SC)", pause=.3)
        dlg = self.app.Window_(title='Using C++ Derived Class')
        dlg.Wait('ready')
        dlg.Done.CloseClick()
        dlg.WaitNot('visible')

        SendKeys("%(H{LEFT}{UP}{ENTER})", pause=.3)
        dlg = self.app.Window_(title='Sample Dialog with spin controls')
        dlg.Wait('ready')
        dlg.Done.CloseClick()
        dlg.WaitNot('visible')
Exemplo n.º 5
0
    def testIncorrectCases(self):
        "Make sure that incorrect key sequences raise an exception"
        DEBUG = 1
        self.assertRaises(KeySequenceError, SendKeys, "{ENTER")
        self.assertRaises(KeySequenceError, SendKeys, "ENTER)")
        self.assertRaises(RuntimeError, SendKeys, "%{Enterius}")
        self.assertRaises(KeySequenceError, SendKeys, "{PAUSE small}")

        try:
            SendKeys("{ENTER five}")
        except KeySequenceError as exc:
            self.assertEquals("invalid repetition count five", str(exc))

        try:
            SendKeys("ENTER}")
        except KeySequenceError as exc:
            self.assertEquals("`}` should be preceeded by `{`", str(exc))
Exemplo n.º 6
0
    def insertImg(img_path, top_dlg):
        """
        @note:
        """
        for i, i_p in enumerate(img_path):
            # SendKeys('{RIGHT}')
            if i >= 1:
                top_dlg["Edit0"].TypeKeys("")
                SendKeys('{TAB}')
                SendKeys('{TAB}')
                SendKeys('{ENTER}')
                # SendKeys('{ENTER}')

            top_dlg['ComboBox2'].TypeKeys('5')
            for x in range(6):
                SendKeys('{TAB}')
                sleep(0.5)

            SendKeys('{ENTER}')
            sleep(1)
            SendKeys(i_p)
            sleep(1)
            SendKeys('{ENTER}')
            sleep(2)
            # SendKeys('{ENTER}')
            # sleep(2)
            # top_dlg["Edit0"].TypeKeys('')
            # SendKeys('{TAB}')
            # SendKeys('{TAB}')
            sleep(10)
Exemplo n.º 7
0
 def add_doc(file_path):
     """
     @note:
     """
     SendKeys('%A')
     SendKeys('{DOWN}')
     SendKeys('{DOWN}')
     SendKeys('{DOWN}')
     SendKeys('{DOWN}')
     SendKeys('{ENTER}')
     sleep(2)
     SendKeys(file_path)
     SendKeys('{ENTER}')
Exemplo n.º 8
0
    def __run_NormalCharacters_with_options(self, **args):
        "Make sure that sending any character in range "

        #unused var: missed = []
        for i in range(32, 127):

            # skip characters that must be escaped
            if chr(i) in (' ', '%', '^', '+', '(', ')', '{', '}', '~'):
                continue

            SendKeys(chr(i) + "{ENTER}", pause=.001, **args)
            received = input_func()

            self.assertEquals(i, ord(received))
def main():
    #subprocess.call(["Twisted-15.2.1.win32-py2.7.exe"])
    exe_file = sys.argv[1]
    app = application.Application()
    appname = os.path.join(os.getcwd(), exe_file)
    print(appname)
    app.start_(appname)
    #app.start(appname)

    print("Sleeping for 2 seconds")
    time.sleep(2)
    print("Step 1")
    first = next_window(app)

    SendKeys('{ENTER}')
    time.sleep(2)

    print("Step 2")
    second = next_window(app)
    SendKeys('%a')
    time.sleep(1)
    SendKeys('{SPACE}')
    time.sleep(1)
    SendKeys('{ENTER}')
    time.sleep(1)

    print("Step 3")
    third = next_window(app)
    time.sleep(1)
    SendKeys('{ENTER}')
    time.sleep(1)

    print("Step 4")
    third = next_window(app)
    time.sleep(1)
    SendKeys('{ENTER}')
    time.sleep(1)

    time.sleep(12)
    print("Step 5")
    finish = finish_window(app)
    time.sleep(1)
    SendKeys('{ENTER}')
    time.sleep(1)
    time.sleep(1)
    SendKeys('{ENTER}')
    time.sleep(1)
Exemplo n.º 10
0
 def getFailimg(file_path, data):
     """
     @note: 将 excel 内的表格制作成图片
     """
     excel = win32.Dispatch('Excel.Application')
     logging.info(file_path)
     wb = excel.Workbooks.open(file_path)
     ws = wb.Worksheets(data[0])
     ws.Range(data[1]).CopyPicture('1', '2')
     ws.Paste(ws.Range("Y1"))
     ws.Shapes("Picture 1").copy()
     sleep(1)
     SendKeys("^V")
     sleep(10)
     SendKeys('{ENTER}')
     SendKeys('{ENTER}')
     # 复制team表格数据
     ws.Range("J1:L25").CopyPicture('1', '2')
     ws.Paste(ws.Range("Y1"))
     ws.Shapes("Picture 2").copy()
     sleep(1)
     SendKeys("^V")
     sleep(10)
     SendKeys('{ENTER}')
     SendKeys('{ENTER}')
     # 复制3张图片
     ws.Range("A13:H47").CopyPicture('1', '2')
     ws.Paste(ws.Range("Y1"))
     ws.Shapes("Picture 3").copy()
     sleep(1)
     SendKeys("^V")
     sleep(10)
     SendKeys('{ENTER}')
     SendKeys('{ENTER}')
     # copy image
     # ws.Shapes('Chart 1').copy()
     # sleep(1)
     # SendKeys("^V")
     # sleep(10)
     # SendKeys('{ENTER}')
     return wb
Exemplo n.º 11
0
    def login(self, mail_path, username, password):
        """
        @note:
        :return:
        """
        self.app = application.Application.start(mail_path)
        sleep(15)

        sleep(3)
        top_dlg = self.app.top_window_()
        sleep(2)
        top_dlg["Edit1"].TypeKeys(username)
        top_dlg["Edit2"].TypeKeys(password)
        sleep(2)
        # print top_dlg.print_control_identifiers()
        logging.info('login.........')
        top_dlg[u'確定'].Click()
        sleep(50)
        SendKeys("{ENTER}")
        sleep(50)
Exemplo n.º 12
0
    def testANSIExtendedCharacters(self):
        "Make sure that sending any character in range "
        os.system("chcp 850")
        matched = 0
        extended_chars = b"\x81\x82\x83\xa1\xe1\xff"
        for char in extended_chars:

            if six.PY3:
                c = str(char)
            else:
                c = char.decode('cp850')
            SendKeys(c + "{ENTER}", pause=.01)
            received = input_func()

            if str(char) == received:
                matched += 1
            else:
                print("expected %s, recieved %s" %
                      (repr(char), repr(received)))

        self.assertEquals(matched, len(extended_chars))
Exemplo n.º 13
0
    def OpenMspaint(self, mspaintPath, imgPath):
        """
        @note: 小画家
        """
        flag = True
        try:
            logging.info('Beginning OpenMspaint!!!')
            Mspaint = application.Application.start(mspaintPath)
            sleep(10)
            SendKeys("^O")
            sleep(10)
            SendKeys(imgPath)
            sleep(4)
            SendKeys("{ENTER}")
            sleep(5)

            # 调整像素
            SendKeys("^W")
            sleep(10)
            top_dlg = Mspaint.top_window_()
            sleep(2)
            top_dlg[u'百分比'].Click()
            sleep(2)
            top_dlg["Edit1"].SetEditText('98')
            sleep(2)
            top_dlg[u'確定'].Click()
            sleep(3)

            SendKeys("^S")
            sleep(10)
            SendKeys("%{F4}")
            logging.info('Finished OpenMspaint!!!')
        except:
            flag = False
            logging.info('Open Mspaint exception')
            logging.info(traceback.format_exc())
        return flag
Exemplo n.º 14
0
 def testNewlinesWithoutNewlines(self):
     "Make sure that with spaces option works"
     SendKeys("\t \t \t\na{ENTER}", pause=.01, with_newlines=False)
     received = input_func()
     self.assertEquals("a", received)
Exemplo n.º 15
0
 def testTab(self):
     "Make sure that with spaces option works"
     SendKeys("{TAB}  {TAB} {ENTER}", pause=.3)
     received = input_func()
     self.assertEquals("\t\t", received)
Exemplo n.º 16
0
 def testTabWithoutTabs(self):
     "Make sure that with spaces option works"
     SendKeys("\t a\t b\t{ENTER}", pause=.1, with_tabs=False)
     received = input_func()
     self.assertEquals("ab", received)
Exemplo n.º 17
0
    def writeContent(self, content, top_dlg):
        """
        @note: content = [0, 1, 2, 3,...]
        """
        top_dlg['ComboBox1'].TypeKeys("%{DOWN}")
        top_dlg['ComboBox1'].Select(u'微軟正黑體')
        # 4--14 5--18
        sleep(0.5)
        top_dlg['ComboBox2'].TypeKeys('5')
        sleep(0.5)
        top_dlg["Edit0"].TypeKeys("")
        SendKeys('{TAB}')
        SendKeys('{TAB}')
        sleep(0.5)

        head = content[0].split(' ')
        for h in head:
            SendKeys(h)
            if h != head[-1]:
                SendKeys('{ }')
        SendKeys('{ENTER}')
        SendKeys('{ENTER}')
        SendKeys('{TAB}')

        SendKeys(u'正')

        top_dlg['ComboBox1'].TypeKeys("%{DOWN}")
        top_dlg['ComboBox1'].Select(u'微軟正黑體')
        # 4--14 5--18
        sleep(0.5)
        top_dlg['ComboBox2'].TypeKeys('5')
        sleep(0.5)
        top_dlg["Edit0"].TypeKeys("")
        SendKeys('{TAB}')
        SendKeys('{TAB}')
        sleep(0.5)

        SendKeys(content[1])
        for x in range(len(content[1]) - 1):
            SendKeys('{LEFT}')
        SendKeys('{BACKSPACE}')
        for y in range(len(content[1]) - 1):
            SendKeys('{RIGHT}')
        SendKeys('{ENTER}')
        SendKeys('{TAB}')
        SendKeys('{ENTER}')
        sleep(5)
        if content[3]:
            if 'attendanceExcel' in content[3]:
                wb = self.getFailimg(content[3], [u'准点下班人数', "A1:H25"])
                wb.Save()
            elif 'dimissionExcel' in content[3]:
                wb = self.getFailimg(content[3], [u'離職狀況', "A1:E10"])
                wb.Save()
            elif 'gsp' in content[3]:
                wb = self.getFailimg(content[3], ['Summary', "A1:H10"])
                wb.Save()
            sleep(15)
            try:
                wb.close()
            except:
                pass
            SendKeys('{ENTER}')
            sleep(10)
        if len(content[2]) > 0:
            self.insertImg(content[2], top_dlg)
Exemplo n.º 18
0
 def testTab(self):
     "Make sure that with spaces option works"
     SendKeys("{TAB}  {TAB} ", pause=.3)
     received = self.ctrl.TextBlock()
     self.assertEquals("\t\t", received)
Exemplo n.º 19
0
 def testNewlinesWithNewlines(self):
     "Make sure that with_newlines option works"
     SendKeys("\t \t \t a~\tb\nc", pause=.5, with_newlines=True)
     received = self.ctrl.TextBlock()
     self.assertEquals("a\r\nb\r\nc", received)
import time
import win32clipboard
import win32com.client
import win32api
from pywinauto.SendKeysCtypes import SendKeys
from pywinauto.SendKeysCtypes import SendInput

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

SendKeys("%D")
time.sleep(0.1)
SendKeys("^C")
time.sleep(0.1)
win32clipboard.OpenClipboard()
url = win32clipboard.GetClipboardData()
win32clipboard.CloseClipboard()
time.sleep(0.1)
print(url)
if "https://www.youtube" in url:
    SendKeys("{TAB}")
    time.sleep(0.1)
    SendKeys("{TAB}")
    time.sleep(0.1)
    SendKeys("{TAB}")
    time.sleep(0.1)
    SendKeys("{TAB}")
    time.sleep(0.1)
    SendKeys("{TAB}")
    time.sleep(0.1)
    SendKeys("{TAB}")
    time.sleep(0.1)
Exemplo n.º 21
0
 def testTabWithoutTabs(self):
     "Make sure that with spaces option works"
     SendKeys("\t a\t b\t", pause=.1, with_tabs=False)
     received = self.ctrl.TextBlock()
     self.assertEquals("ab", received)
Exemplo n.º 22
0
def f12_():
    SendKeys("{F12}")
Exemplo n.º 23
0
 def testNewlinesWithoutNewlines(self):
     "Make sure that with_newlines option works"
     SendKeys("\t \t \t\na", pause=.01, with_newlines=False)
     received = self.ctrl.TextBlock()
     self.assertEquals("a", received)
Exemplo n.º 24
0
 def testRepetition(self):
     "Make sure that repeated action works"
     SendKeys("{TAB 3}{PAUSE 0.5}{F 2}", pause=.3)
     received = self.ctrl.TextBlock()
     self.assertEquals("\t\t\tFF", received)
Exemplo n.º 25
0
import webbrowser
import codecs
import win32api
import time
import win32clipboard
from pywinauto.SendKeysCtypes import SendKeys
from pywinauto.SendKeysCtypes import SendInput

with codecs.open('secondary-key.tmp', 'r', encoding='utf-8') as fo:
    for line in fo:
        value = line[10:]

webbrowser.open("https://www.google.com/maps/place/" + value)
time.sleep(2)
SendKeys("%D")
time.sleep(2)
SendKeys("^C")
win32clipboard.OpenClipboard()
url = win32clipboard.GetClipboardData()
win32clipboard.CloseClipboard()
Exemplo n.º 26
0
 def testCharsThatMustBeEscaped(self):
     "Make sure that escaping characters works"
     SendKeys("{%}{^}{+}{(}{)}{{}{}}{~}")
     received = self.ctrl.TextBlock()
     self.assertEquals("%^+(){}~", received)
Exemplo n.º 27
0
 def testCharsThatMustBeEscaped(self):
     "Make sure that escaping characters works"
     SendKeys("{%}{^}{+}{(}{)}{{}{}}{~}{ENTER}")
     received = input_func()
     self.assertEquals("%^+(){}~", received)
Exemplo n.º 28
0
 def testSpaceWithoutSpaces(self):
     "Make sure that with spaces option works"
     SendKeys(" \t \t ", pause=.001, with_spaces=False)
     received = self.ctrl.TextBlock()
     self.assertEquals("", received)
Exemplo n.º 29
0
 def testSpaceWithoutSpaces(self):
     "Make sure that with spaces option works"
     SendKeys(" \t \t {ENTER}", pause=.001, with_spaces=False)
     received = input_func()
     self.assertEquals("", received)
Exemplo n.º 30
0
def f11_():
    SendKeys("{F11}")