本文目錄一覽:
python 如何實現運行後單擊屏幕的任意位置返回滑鼠點擊坐標的位置?
你好,下面是一個對應的代碼,不過你需要安裝pythoncom和pyHook。
import pythoncom, pyHook
def onMouseEvent(event):
print “Position:”, event.Position
return True
def main():
hm = pyHook.HookManager()
hm.HookKeyboard()
hm.MouseAllButtonsDown = onMouseEvent
hm.MouseAllButtonsUp = onMouseEvent
hm.HookMouse()
pythoncom.PumpMessages()
if __name__ == “__main__”:
main()
Python3怎麼模擬滑鼠點擊?
import win32api,win32con
def click(x,y):
win32api.SetCursorPos((x,y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)
(x,y)是你需要點擊的位置,屏幕左上角為(0,0)
python如何在手機上點擊多項選擇題的選項
你可以在開發者選項中打開指針位置,這樣就很容易去獲取界面上各個圖標的具體位置了。建議是先獲取手機解析度,然後根據解析度去計算要點擊的位置。
點擊操作driver有click()方法,如果沒有className或者resource-id,使用swipe方法,參考如下:
##獲取手機屏幕解析度
x = self.driver.get_window_size()[‘width’]
y = self.driver.get_window_size()[‘height’]
x = int(x*0.1)
y = int(y*0.1)
self.driver.swipe(x, y, x, y,1)
#這裡的xy就是你UI界面上圖標對應的坐標,時間非常短,1毫秒,模擬點擊了。
如果別人有更好的方法,你就用別人的,僅供參考。
當然tap也可以,doc如下:
“””Taps on an particular place with up to five fingers, holding
for a
certain time
:Args:
– positions – an array of tuples representing the x/y
coordinates of
the fingers to tap. Length can be up to five.
– duration – (optional) length of time to tap, in ms
:Usage:
driver.tap([(100, 20), (100, 60), (100, 100)], 500)
“””
python怎麼模擬鍵盤操作?
實現了一個最簡單的輸入密碼,enter進入的簡單鍵盤操作登錄過程,具體代碼如下:
· 滑鼠點擊
有m.click(x, y, button, n) — 點擊,想x,y坐標,button:-1表示左鍵,-2表示右鍵,n:默認1次,2雙擊
m.move(x, y) — 滑鼠移動
m.screen_size() — 獲取屏幕尺寸
· 鍵盤操作
k.type_string(‘abcdefg’) –輸入內容
k.press_key(‘a’) –按a鍵
k.release_key(‘a’) –鬆開a鍵
k.tap_key(‘a’) –點擊a鍵
k.tap_key(‘a’, n=2, interval=5) –點擊a鍵2次,每次間隔5秒
k.tap_key(k.function_keys[5]) –功能鍵F5
k.press_keys([k.alt_key, ‘a’]) –組合按鍵
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/229284.html