C#用mouse_event模拟鼠标点击的问题
生活随笔
收集整理的這篇文章主要介紹了
C#用mouse_event模拟鼠标点击的问题
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1、首先添加using System.Runtime.InteropServices;
2、為鼠標(biāo)添加模擬點(diǎn)擊的各種參數(shù)
? //鼠標(biāo)事件??因?yàn)槲矣玫牟欢?#xff0c;所以其他參數(shù)沒有寫
| 1 2 3 4 5 6 7 8 | ???private?readonly?int?MOUSEEVENTF_LEFTDOWN?=?0x0002;//模擬鼠標(biāo)移動(dòng) ???private?readonly?int?MOUSEEVENTF_MOVE?=?0x0001;//模擬鼠標(biāo)左鍵按下 ???private?readonly?int?MOUSEEVENTF_LEFTUP?=?0x0004;//模擬鼠標(biāo)左鍵抬起 ???private?readonly?int?MOUSEEVENTF_ABSOLUTE?=?0x8000;//鼠標(biāo)絕對(duì)位置 ???private?readonlyint?MOUSEEVENTF_RIGHTDOWN?=?0x0008;?//模擬鼠標(biāo)右鍵按下? ???private?readonlyint?MOUSEEVENTF_RIGHTUP?=?0x0010;?//模擬鼠標(biāo)右鍵抬起? ???private?readonlyint?MOUSEEVENTF_MIDDLEDOWN?=?0x0020;?//模擬鼠標(biāo)中鍵按下? ???private?readonlyint?MOUSEEVENTF_MIDDLEUP?=?0x0040;//?模擬鼠標(biāo)中鍵抬起 |
3、為鼠標(biāo)點(diǎn)擊添加點(diǎn)擊函數(shù)????????
| 1 2 3 4 5 6 | public?static?extern?void?mouse_event(int?dwFlags,?int?dx,?int?dy,?int?dwData,?int?dwExtraInfo); ?????????private?void?button2_Click(object?sender,?EventArgs?e)????????{????????????int?x?=?int.Parse(textBox1.Text);????????????int?y?=?int.Parse(textBox2.Text); //絕對(duì)位置????????????mouse_event(MOUSEEVENTF_MOVE?|?MOUSEEVENTF_ABSOLUTE,?x?*?65535?/?1600,?y?*?65535?/?900,?0,?0);//移動(dòng)到需要點(diǎn)擊的位置????????????mouse_event(MOUSEEVENTF_LEFTDOWN?|?MOUSEEVENTF_ABSOLUTE,?x?*?65535?/?1600,?y?*?65535?/?900,?0,?0);//點(diǎn)擊????????????mouse_event(MOUSEEVENTF_LEFTUP?|?MOUSEEVENTF_ABSOLUTE,?x?*?65535?/?1600,?y?*?65535?/?900,?0,?0);//抬起 //相對(duì)位置??指的是相對(duì)于當(dāng)前鼠標(biāo)的相對(duì)位置 ????????????mouse_event(MOUSEEVENTF_MOVE?,?x?,?y,?0,?0);//移動(dòng)????????????mouse_event(MOUSEEVENTF_LEFTDOWN?,?x?,?y,?0,?0);//點(diǎn)擊????????????mouse_event(MOUSEEVENTF_LEFTUP?,?x?,?y?,?0,?0);//抬起 ????????} |
總結(jié)
以上是生活随笔為你收集整理的C#用mouse_event模拟鼠标点击的问题的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 爱是什么(说一说爱是什么的简介)
- 下一篇: c# char unsigned_dll