Python滑鼠模擬

2022-05-14 11:45:12 字數 1352 閱讀 9464

有時候我們需要使用python執行一些指令碼,可能需要讓程式自動按鍵或自動點選滑鼠,下面的**實現了對鍵盤的模擬按鍵,

需要安裝pypiwin32,當然也可以直接用ctypes來實現。

輸入:pip install pypiwin32 安裝pypiwin32。

#

coding=utf-8

import

win32api

import

win32con

import

win32gui

defmove(x, y):

"""函式功能:移動滑鼠到指定位置

參 數:x:x座標

y:y座標

"""win32api.setcursorpos((x, y))

defget_cur_pos():

"""函式功能:獲取當前滑鼠座標

"""p=

pos =win32gui.getcursorpos()

p['x

']=pos[0]

p['y

']=pos[1]

return

pdef

left_click():

"""函式功能:滑鼠左鍵點選

"""win32api.mouse_event(win32con.mouseeventf_leftdown |win32con.mouseeventf_leftup, 0, 0, 0, 0)

defright_click():

"""函式功能:滑鼠右鍵點選

"""win32api.mouse_event(win32con.mouseeventf_rightdown |win32con.mouseeventf_rightup, 0, 0, 0, 0)

defleft_down():

"""函式功能:滑鼠左鍵按下

"""win32api.mouse_event(win32con.mouseeventf_leftdown, 0, 0, 0, 0)

defleft_up():

"""函式功能:滑鼠左鍵抬起

"""win32api.mouse_event(win32con.mouseeventf_leftup, 0, 0, 0, 0)

defright_down():

"""函式功能:滑鼠右鍵按下

"""win32api.mouse_event(win32con.mouseeventf_rightdown, 0, 0, 0, 0)

defright_up():

"""函式功能:滑鼠右鍵抬起

"""win32api.mouse_event(win32con.mouseeventf_rightup, 0, 0, 0, 0)

python模擬滑鼠中軸滾動

網上對這個說的不多,自己搜了些帖子,寫下自己的經驗 需要用到的模組win32api win32con,安裝pywin32即可 下面這個方法可模擬滑鼠中軸滑動,1代表頁面向下,1代表向上。網上說了可以指定任意數,親測後發現程式只識別正數 負數,正數向上移動乙個位置,負數向下移動乙個位置,跟值大小沒關係...

C 模擬滑鼠

using system using system.collections.generic using system.componentmodel using system.data using system.drawing using system.text using system.window...

C 滑鼠模擬

void mousemove int x,int y 滑鼠移動到指定位置 input.type input mouse input.mi.dwflags mouseeventf move mouseeventf absolute input.mi.dx fx input.mi.dy fy sendi...