C winform 獲取滑鼠點選位置

2022-07-17 03:27:13 字數 2981 閱讀 4729

說明:該篇隨筆的**內容並非出自本人,是在其他**搜尋的,出處已經不記得了,本次隨筆只為記錄,目的幫助自己,幫助他人。

實現的原理也不做多的贅述,直接上**。

第乙個類是需要用到的windows api

public

class

win32api

[structlayout(layoutkind.sequential)]

public

class

mousehookstruct

public

delegate

int hookproc(int

ncode, intptr wparam, intptr lparam);

//安裝鉤子

[dllimport("

user32.dll

", charset = charset.auto, callingconvention =callingconvention.stdcall)]

public

static

extern

int setwindowshookex(int idhook, hookproc lpfn, intptr hinstance, int

threadid);

//解除安裝鉤子

[dllimport("

user32.dll

", charset = charset.auto, callingconvention =callingconvention.stdcall)]

public

static

extern

bool unhookwindowshookex(int

idhook);

//呼叫下乙個鉤子

[dllimport("

user32.dll

", charset = charset.auto, callingconvention =callingconvention.stdcall)]

public

static

extern

int callnexthookex(int idhook, int

ncode, intptr wparam, intptr lparam);

}

windows api

第二個類是用於監控滑鼠移動,滑鼠點選的

public

class

mousehook

set }}}

private

inthhook;

private

const

int wm_lbuttondown = 0x201

;

private

const

int wm_rbuttondown = 0x204

;

public

const

int wh_mouse_ll = 14

;

public

win32api.hookproc hproc;

public

mousehook()

public

intsethook()

public

void

unhook()

private

int mousehookproc(int

ncode, intptr wparam, intptr lparam)

else

var e = new mouseeventargs(button, clickcount, point.x, point.y, 0

); mouseclickevent(

this

, e);

}this.point = new

point(mymousehookstruct.pt.x, mymousehookstruct.pt.y);

return

win32api.callnexthookex(hhook, ncode, wparam, lparam);}}

public

delegate

void mousemovehandler(object

sender, mouseeventargs e);

public

event

mousemovehandler mousemoveevent;

public

delegate

void mouseclickhandler(object

sender, mouseeventargs e);

public

event

mouseclickhandler mouseclickevent;

}

mousehook

最後直接在窗體中呼叫重寫的事件即可

獲取滑鼠點選事件

設定觸控模式 node settouchmode cc.touch mode one by one 單點觸控 或者 node settouchmode cc.touch mode all at once 多點觸控 是否啟用觸控 預設值 false node settouchenabled true ...

模擬滑鼠點選事件

今天上12306購票,可被氣得不輕,首先登陸人數受到了限制,其次買到票還有個排隊等待神馬的,先不說裡頭有沒有貓膩,電腦直接操作的,需要等待30分鐘以上嗎?神馬查詢語言要執行30分鐘才能得到個結果出來?贊同網上的言論 相比較而言,之前的搶票更能接受一些 上面是tackbar,用於隨時調整點選的時間間隔...

MFC模擬滑鼠點選

mfc 工程 把以下 放到你想要響應的函式裡面就行 cpoint pt getcursorpos pt 獲取滑鼠在螢幕的當前位置 setcursorpos 100,200 移動到某點座標 mouse event mouseeventf rightdown,0,0,0,0 點下右鍵 mouse eve...