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
#Click Current Place
python类keybd_event()的实例源码
ctrl_omnipeek.py 文件源码
项目:Automation-Framework-for-devices
作者: tok-gogogo
项目源码
文件源码
阅读 36
收藏 0
点赞 0
评论 0
def shortcut_keys(self,list_key=[]):
for x in list_key:
tmp = self.dic_keycode(x)
try:
win32api.keybd_event(tmp,0,0,0)
except Exception ,excet_str:
log_print( excet_str)
for x in list_key:
tmp = self.dic_keycode(x)
try:
win32api.keybd_event(tmp,0,win32con.KEYEVENTF_KEYUP,0)
except Exception ,excet_str:
log_print( excet_str)
def toggleMedia():
win32api.keybd_event(const.VK_MEDIA_PLAY_PAUSE, const.HWCODE)
def FX_KeybdPress(virtual_key_code):
win32api.keybd_event(virtual_key_code, 0, 0, 0)
def FX_KeybdRelease(virtual_key_code):
win32api.keybd_event(virtual_key_code, 0, win32con.KEYEVENTF_KEYUP, 0)
def press_key(self, character=''):
"""
Press a given character key.
"""
try:
shifted = self.is_char_shifted(character)
except AttributeError:
win32api.keybd_event(character, 0, 0, 0)
else:
if shifted:
win32api.keybd_event(self.shift_key, 0, 0, 0)
char_vk = win32api.VkKeyScan(character)
win32api.keybd_event(char_vk, 0, 0, 0)
def release_key(self, character=''):
"""
Release a given character key.
"""
try:
shifted = self.is_char_shifted(character)
except AttributeError:
win32api.keybd_event(character, 0, KEYEVENTF_KEYUP, 0)
else:
if shifted:
win32api.keybd_event(self.shift_key, 0, KEYEVENTF_KEYUP, 0)
char_vk = win32api.VkKeyScan(character)
win32api.keybd_event(char_vk, 0, KEYEVENTF_KEYUP, 0)
rw_Excel_FLOW_bak_ok.py 文件源码
项目:Automation-Framework-for-devices
作者: tok-gogogo
项目源码
文件源码
阅读 23
收藏 0
点赞 0
评论 0
def Onu_login(self,FlowName):
print 'onu_login fuction'
if self.Onu_login_Flag == 1 :
return True
ap_name = FlowName.split('_')[-1]
if ap_name =='ONU':
login_username = LOGIN_USERNAME_GONGJIN
login_password = LOGIN_PASSWORD_GONGJIN
print 'GONGJIN:login_username--',login_username
print 'GONGJIN:login_password--',login_password
test_win = win_gui()
hwnd = win32gui.FindWindow('#32770',None)
print 'hwnd is ',hwnd
if hwnd < 1:
log_public(WEB_ERR_NO_0020)
self.m_ERROR_MSG = WEB_ERR_NO_0020
return False
else:
win32api.Sleep(100)
win32api.keybd_event(18,0,0,0);
win32api.keybd_event(85,0,0,0);
win32api.Sleep(100)
win32api.keybd_event(85,0,win32con.KEYEVENTF_KEYUP,0);
win32api.keybd_event(18,0,win32con.KEYEVENTF_KEYUP,0);
win32api.Sleep(100)
shell = win32com.client.Dispatch("WScript.Shell")
shell.SendKeys(login_username)
win32api.Sleep(100)
win32api.keybd_event(18,0,0,0);
win32api.keybd_event(80,0,0,0);
win32api.Sleep(100)
win32api.keybd_event(80,0,win32con.KEYEVENTF_KEYUP,0);
win32api.keybd_event(18,0,win32con.KEYEVENTF_KEYUP,0);
win32api.Sleep(300)
shell.SendKeys(login_password)
win32api.Sleep(100)
win32api.keybd_event(13,0,0,0);
win32api.Sleep(100)
win32api.keybd_event(13,0,win32con.KEYEVENTF_KEYUP,0);
win32api.Sleep(100)
return True
ctrl_waveQoE.py 文件源码
项目:Automation-Framework-for-devices
作者: tok-gogogo
项目源码
文件源码
阅读 22
收藏 0
点赞 0
评论 0
def choose_conf_file(self):
#get control of waveQoE window.
hwnd3 = win32gui.FindWindow(WAVEQOE_CLASS,None)
print 'hwnd3',hwnd3
time.sleep(0.5)
#set waveQoE window to top.
win32gui.SetForegroundWindow(hwnd3)
time.sleep(0.5)
#move waveQoE window to top left corner.
win32gui.MoveWindow(hwnd3,0,0,1448,878,1)
#send Alt+F to open 'File' in menu bar.
win32api.Sleep(1000)
win32api.keybd_event(18,0,0,0); #18Alt?
win32api.keybd_event(70,0,0,0); #70F?
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 O to open 'open' window.
win32api.keybd_event(79,0,0,0); #79O?
win32api.Sleep(1000)
win32api.keybd_event(79,0,win32con.KEYEVENTF_KEYUP,0);
win32api.Sleep(1000)
#choose config file and open it.
self.myobj.Find_Gui_edit(str_app = 'Open',control_class = 'ComboBox',filename = self.conf_file_dir,control_name = '',stop_flag = '0')
self.myobj.Find_Gui_button(str_app = 'Open',control_class = 'Button',control_name = '(&O)')
time.sleep(0.5)
hwnd4 = win32gui.FindWindow('#32770','Open')
print 'hwnd4: ',hwnd4
if hwnd4 > 0:
log_public(ERR_NO_0006)
self.m_ERROR_MSG = ERR_NO_0006
self.myobj.Find_Gui_button(str_app = 'Open',control_class = 'Button',control_name = '?')
time.sleep(0.5)
self.myobj.Find_Gui_button(str_app = 'Open',control_class = 'Button',control_name = '?')
time.sleep(0.5)
self.close_waveQoE()
print 'close_waveqoe'
return False
else:
print 'conf_file is correct.'
return True
#-----------------------------------------------------------------------------
# Name: Mouse_LB_click
# purpose: click the mouse's left butten.
# explain:
# Author: yuanwen
#
# Created: 2013/07/5
#-----------------------------------------------------------------------------
ctrl_waveQoE.py 文件源码
项目:Automation-Framework-for-devices
作者: tok-gogogo
项目源码
文件源码
阅读 30
收藏 0
点赞 0
评论 0
def close_waveQoE(self):
#get the handle of waveQoE window.
try:
hwnd6 = win32gui.FindWindow(WAVEQOE_CLASS,None)
print 'hwnd6:',hwnd6
time.sleep(1)
#set the waveQoE 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 = WAVEQOE_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); #18Alt?
win32api.keybd_event(70,0,0,0); #70F?
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 waveQoE window.
win32api.keybd_event(88,0,0,0); #88X?
win32api.Sleep(1000)
win32api.keybd_event(88,0,win32con.KEYEVENTF_KEYUP,0);
win32api.Sleep(1000)
if self.timeout == 1:
#send Alt+Y to exit waveQoE without save.
win32api.keybd_event(18,0,0,0); #18Alt?
win32api.keybd_event(89,0,0,0); #89Y?
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 waveQoE without save.
win32api.keybd_event(18,0,0,0); #18Alt?
win32api.keybd_event(78,0,0,0); #78N?
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
rw_Excel_FLOW.py 文件源码
项目:Automation-Framework-for-devices
作者: tok-gogogo
项目源码
文件源码
阅读 24
收藏 0
点赞 0
评论 0
def Onu_login(self,FlowName):
print 'onu_login fuction'
if self.Onu_login_Flag == 1 :
return True
ap_name = FlowName.split('_')[-1]
if ap_name =='ONU':
login_username = LOGIN_USERNAME_GONGJIN
login_password = LOGIN_PASSWORD_GONGJIN
print 'GONGJIN:login_username--',login_username
print 'GONGJIN:login_password--',login_password
test_win = win_gui()
hwnd = win32gui.FindWindow('#32770',None)
print 'hwnd is ',hwnd
if hwnd < 1:
log_public(WEB_ERR_NO_0020)
self.m_ERROR_MSG = WEB_ERR_NO_0020
return False
else:
win32api.Sleep(100)
win32api.keybd_event(18,0,0,0);
win32api.keybd_event(85,0,0,0);
win32api.Sleep(100)
win32api.keybd_event(85,0,win32con.KEYEVENTF_KEYUP,0);
win32api.keybd_event(18,0,win32con.KEYEVENTF_KEYUP,0);
win32api.Sleep(100)
shell = win32com.client.Dispatch("WScript.Shell")
shell.SendKeys(login_username)
win32api.Sleep(100)
win32api.keybd_event(18,0,0,0);
win32api.keybd_event(80,0,0,0);
win32api.Sleep(100)
win32api.keybd_event(80,0,win32con.KEYEVENTF_KEYUP,0);
win32api.keybd_event(18,0,win32con.KEYEVENTF_KEYUP,0);
win32api.Sleep(300)
shell.SendKeys(login_password)
win32api.Sleep(100)
win32api.keybd_event(13,0,0,0);
win32api.Sleep(100)
win32api.keybd_event(13,0,win32con.KEYEVENTF_KEYUP,0);
win32api.Sleep(100)
return True
def first_test_case(self,test_case = r"E:\UFTTestCase\EMS_Test\EMS_FUN_000012\DemoTest\DemoTest"):
WINDOW_TITLE = u'HP Unified Functional Testing'
self.app[WINDOW_TITLE].TypeKeys(u'^O')
time.sleep(2)
try:
shell = win32com.client.Dispatch("WScript.Shell")
shell.SendKeys(test_case)
except Exception,e:
print e
time.sleep(2)
self.app[u'Open Test'][u'Open'].Click()
test_win = win_gui()
cnt = 0
while cnt<60:
try:
hwnd = 0
hwnd = test_win.find_main_window_end(test_case)
#print '12 = ',hwnd
if hwnd>0:
break
except Exception,e:
cnt = cnt + 1
time.sleep(1)
pass
win32api.keybd_event(116,0,0,0)
win32api.Sleep(2)
win32api.keybd_event(116,0,win32con.KEYEVENTF_KEYUP,0)
time.sleep(2)
win32api.keybd_event(13,0,0,0)
win32api.Sleep(2)
win32api.keybd_event(13,0,win32con.KEYEVENTF_KEYUP,0)
cnt = 0
result = False
while cnt<60:
try:
hwnd = 0
hwnd = test_win.find_main_window_end('HP Run Results Viewer')
if hwnd>0:
result = True
break
except Exception,e:
print e
cnt = cnt + 1
time.sleep(1)
pass
return result
def loadrunner_Scenario(self,app = 'D:\\Program Files\\HP\\LoadRunner\\bin\\Wlrun.exe',scriptname ='Scenario1.lrs'):
count = '2'
#app = 'D:\\Program Files\\HP\\LoadRunner\\bin\\Wlrun.exe'
self.startapp(app)
self.sleep(count)
str_app = 'New Scenario'
list = []
result = False
try:
list = self.Find_Gui_window(str_app)
except Exception ,exc_str:
log_print(exc_str)
return False
if len(list)>0:
print list
control_name = 'Cancel'
control_class = 'Button'
self.Find_Gui_button(str_app,control_class,control_name)
str_app = 'HP LoadRunner Controller'
self.app_first(str_app)
self.shortcut_keys(['Ctrl','O'])
str_app = 'Open Scenario'
self.Find_Gui_edit(str_app,control_class='Edit',filename=scriptname,stop_flag='1')
time.sleep(2)
self.app_first(str_app)
control_name = '´ò¿ª(&O)'
control_class = 'Button'
self.Find_Gui_button(str_app,control_class,control_name)
time.sleep(10)
str_app = 'HP LoadRunner Controller'
self.app_first(str_app)
self.shortcut_keys(['F5'])
time.sleep(1)
list_a = self.Find_Gui_window()
if len(list_a)>0:
control_class = 'Button'
control_name = 'ÊÇ(&Y)'
try:
result = self.Find_Gui_button(list_a[0],control_class,control_name)
except:
return False
else:
result = True
return result
#self.shortcut_keys(['Ctrl','O'])
'''
win32api.keybd_event(17,0,0,0) #ctrl¼üλÂëÊÇ17
win32api.keybd_event(79,0,0,0) #o¼üλÂëÊÇ86
win32api.keybd_event(79,0,win32con.KEYEVENTF_KEYUP,0) #ÊͷŰ´¼ü
win32api.keybd_event(17,0,win32con.KEYEVENTF_KEYUP,0)
'''
#str_app = 'New Scenario'
ctrl_waveApps.py 文件源码
项目:Automation-Framework-for-devices
作者: tok-gogogo
项目源码
文件源码
阅读 20
收藏 0
点赞 0
评论 0
def choose_conf_file(self):
#get control of waveApps window.
hwnd3 = win32gui.FindWindow(WAVEApps_CLASS,None)
print 'hwnd3',hwnd3
time.sleep(0.5)
#set waveApps window to top.
win32gui.SetForegroundWindow(hwnd3)
time.sleep(0.5)
#move waveApps window to top left corner.
win32gui.MoveWindow(hwnd3,0,0,1448,878,1)
#send Alt+F to open 'File' in menu bar.
win32api.Sleep(1000)
win32api.keybd_event(18,0,0,0); #18Alt?
win32api.keybd_event(70,0,0,0); #70F?
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 O to open 'open' window.
win32api.keybd_event(79,0,0,0); #79O?
win32api.Sleep(1000)
win32api.keybd_event(79,0,win32con.KEYEVENTF_KEYUP,0);
win32api.Sleep(1000)
#choose config file and open it.
self.myobj.Find_Gui_edit(str_app = 'Open',control_class = 'ComboBox',filename = self.conf_file_dir,control_name = '',stop_flag = '0')
self.myobj.Find_Gui_button(str_app = 'Open',control_class = 'Button',control_name = '(&O)')
time.sleep(0.5)
hwnd4 = win32gui.FindWindow('#32770','Open')
print 'hwnd4: ',hwnd4
if hwnd4 > 0:
log_public(ERR_NO_0006)
self.m_ERROR_MSG = ERR_NO_0006
self.myobj.Find_Gui_button(str_app = 'Open',control_class = 'Button',control_name = '?')
time.sleep(0.5)
self.myobj.Find_Gui_button(str_app = 'Open',control_class = 'Button',control_name = '?')
time.sleep(0.5)
self.close_waveApps()
print 'close_waveApps'
return False
else:
print 'conf_file is correct.'
return True
#-----------------------------------------------------------------------------
# Name: Mouse_LB_click
# purpose: click the mouse's left butten.
# explain:
# Author: yuanwen
#
# Created: 2013/07/5
#-----------------------------------------------------------------------------
ctrl_waveApps.py 文件源码
项目:Automation-Framework-for-devices
作者: tok-gogogo
项目源码
文件源码
阅读 19
收藏 0
点赞 0
评论 0
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); #18Alt?
win32api.keybd_event(70,0,0,0); #70F?
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); #88X?
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); #18Alt?
win32api.keybd_event(89,0,0,0); #89Y?
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); #18Alt?
win32api.keybd_event(78,0,0,0); #78N?
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
def OpenWiressResourse(self):
log_print( ">>OpenWiressResourse" )
app = None
LstIDX =[0]
RET = None
app = self.OpenNetDialogAndSelectIcon(LstIDX)
time.sleep(1)
print 'OpenWiressResourse OpenNetDialogAndSelectIcon',LstIDX
try:
#Open "resorse" dialog
#-app[KEY_NETDIALOG].TypeKeys(KEY_NETDIALOG_FILE,pause=KEY_PAUSH_SLEEP_TIEM)
#-app[KEY_NETDIALOG].TypeKeys(KEY_NETDIALOG_FILE_RESOSE,pause=KEY_PAUSH_SLEEP_TIEM)
print 'OpenWiressResourse here'
RET =app[KEY_NETDIALOG].ListViewWrapper.GetItemRect(LstIDX[0])
print 'RET',RET
#myMenu = [KEY_POP_MENU_RSE]
#self.PopMenuClick(app,KEY_NETDIALOG,myMenu,RET)
#self.wingui.shortcut_keys(['Alt','F'])
time.sleep(1)
win32api.keybd_event(18,0,0,0)
win32api.keybd_event(70,0,0,0)
win32api.keybd_event(70,0,win32con.KEYEVENTF_KEYUP,0)
win32api.keybd_event(18,0,win32con.KEYEVENTF_KEYUP,0)
time.sleep(1)
#self.wingui.shortcut_keys(['R'])
win32api.keybd_event(82,0,0,0)
win32api.keybd_event(82,0,win32con.KEYEVENTF_KEYUP,0)
time.sleep(3)
#close "net connect" dialog
#-app[KEY_NETDIALOG].TypeKeys(KEY_NETDIALOG_FILE,pause=KEY_PAUSH_SLEEP_TIEM)
#-app[KEY_NETDIALOG].TypeKeys(KEY_NETDIALOG_FILE_CLOSE,pause=KEY_PAUSH_SLEEP_TIEM)
#self.closeExistDialog()
#connect to "resorse" dialog
app=application.Application().connect_(title_re=KEY_FIND_WIRESS_NAME_PROPERTY )
print 'OpenWiressResourse here 23'
time.sleep(1)
except Exception ,excet_str:
log_print( excet_str)
#self.m_ERROR_MSG = ERR_024
app = None
return app
#014