import os, time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import ctypes
import time
bstack="C:\\Program Files (x86)\\BlueStacks\\HD-StartLauncher.exe"
# chromedriver 다운로드 후 경로 지정 https://sites.google.com/a/chromium.org/chromedriver/downloads
chromedirver="C:\\Users\\bitec101\\Downloads\\chromedriver_win32\\chromedriver"
os.environ["webdriver.chrome.driver"]=chromedirver
chrome_options=webdriver.ChromeOptions()
chrome_options.add_argument('--incognito --start-maximized') # private mode, 전체화면 옵션 적용
driver=webdriver.Chrome(chromedirver,chrome_options=chrome_options)
pyRefPath="file:///C:/Users/bitec101/Downloads/python-3.4.3-docs-html/python-3.4.3-docs-html/library/index.html"
SendInput = ctypes.windll.user32.SendInput
PUL = ctypes.POINTER(ctypes.c_ulong)
class KeyBdInput(ctypes.Structure):
_fields_ = [("wVk", ctypes.c_ushort),
("wScan", ctypes.c_ushort),
("dwFlags", ctypes.c_ulong),
("time", ctypes.c_ulong),
("dwExtraInfo", PUL)]
class HardwareInput(ctypes.Structure):
_fields_ = [("uMsg", ctypes.c_ulong),
("wParamL", ctypes.c_short),
("wParamH", ctypes.c_ushort)]
class MouseInput(ctypes.Structure):
_fields_ = [("dx", ctypes.c_long),
("dy", ctypes.c_long),
("mouseData", ctypes.c_ulong),
("dwFlags", ctypes.c_ulong),
("time",ctypes.c_ulong),
("dwExtraInfo", PUL)]
class Input_I(ctypes.Union):
_fields_ = [("ki", KeyBdInput),
("mi", MouseInput),
("hi", HardwareInput)]
class Input(ctypes.Structure):
_fields_ = [("type", ctypes.c_ulong),
("ii", Input_I)]
def PressKey(hexKeyCode):
extra = ctypes.c_ulong(0)
ii_ = Input_I()
ii_.ki = KeyBdInput( hexKeyCode, 0x48, 0, 0, ctypes.pointer(extra) )
x = Input( ctypes.c_ulong(1), ii_ )
ctypes.windll.user32.SendInput(1, ctypes.pointer(x), ctypes.sizeof(x))
def ReleaseKey(hexKeyCode):
extra = ctypes.c_ulong(0)
ii_ = Input_I()
ii_.ki = KeyBdInput( hexKeyCode, 0x48, 0x0002, 0, ctypes.pointer(extra) )
x = Input( ctypes.c_ulong(1), ii_ )
ctypes.windll.user32.SendInput(1, ctypes.pointer(x), ctypes.sizeof(x))
def PressAltTab():
PressKey(0x012) #Alt
PressKey(0x09) #Tab
time.sleep(1) #optional : if you want to see the atl-tab overlay
ReleaseKey(0x09) #~Tab
ReleaseKey(0x012) #~Alt
def new_tab(tab_num):
driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 't')
driver.switch_to_window(driver.window_handles[-1])
tab_num=driver.current_window_handle
driver.switch_to_window(tab_num)
def main():
driver.get('http://tweetdeck.twitter.com')
tab1=driver.current_window_handle
new_tab("tab2")
driver.get('http://twitter.com')
new_tab("tab3")
driver.get('http://tistory.com')
new_tab("tab4")
driver.get(pyRefPath)
os.startfile(bstack)
driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + Keys.TAB)
time.sleep(1)
PressAltTab()
if __name__=="__main__":
main()
'Python > Python 3.x' 카테고리의 다른 글
pressing ALT+TAB in windows (0) | 2015.09.25 |
---|---|
converting .py to .exe (0) | 2015.09.23 |
How do I execute a program from python? os.system fails due to spaces in path (0) | 2015.09.23 |
timer_with_Lock.py (0) | 2015.05.08 |
asyncWrite.py (0) | 2015.05.08 |