34 Star 104 Fork 20

yinkaisheng / PythonUIAutomation4Windows

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
automation_calculator.py 1.43 KB
一键复制 编辑 原始数据 按行查看 历史
yinkaisheng 提交于 2016-11-08 12:11 . add calculator demo
#!python3
# -*- coding: utf-8 -*-
import time
import subprocess
import automation
def main():
char2Id = {
'0' : '130',
'1' : '131',
'2' : '132',
'3' : '133',
'4' : '134',
'5' : '135',
'6' : '136',
'7' : '137',
'8' : '138',
'9' : '139',
'.' : '84',
'+' : '93',
'-' : '94',
'*' : '92',
'/' : '91',
'=' : '121',
'(' : '128',
')' : '129',
}
subprocess.Popen('calc')
calcWindow = automation.WindowControl(searchDepth = 1, ClassName = 'CalcFrame')
calcWindow.SetTopmost()
calcWindow.SendKeys('{Alt}2')
char2Button = {}
for key in char2Id:
char2Button[key] = calcWindow.ButtonControl(AutomationId = char2Id[key])
def calc(expression):
expression = ''.join(expression.split())
if not expression.endswith('='):
expression += '='
for char in expression:
automation.Logger.Write(char, writeToFile = False)
char2Button[char].Click(waitTime = 0.05)
calcWindow.SendKeys('{Ctrl}c', waitTime = 0)
result = automation.Win32API.GetClipboardText()
automation.Logger.WriteLine(result, automation.ConsoleColor.Cyan, writeToFile = False)
time.sleep(1)
calc('2*3.14159*10')
calc('1234 * (4 + 5 + 6) - 78 / 90')
if __name__ == '__main__':
main()
Python
1
https://gitee.com/yinkaisheng/PythonUIAutomation4Windows.git
git@gitee.com:yinkaisheng/PythonUIAutomation4Windows.git
yinkaisheng
PythonUIAutomation4Windows
PythonUIAutomation4Windows
master

搜索帮助