用应用程序模拟键盘和鼠标按键Keyboard and mouse buttons are simulated with Applications.docx
- 文档编号:11284952
- 上传时间:2023-02-26
- 格式:DOCX
- 页数:12
- 大小:17.82KB
用应用程序模拟键盘和鼠标按键Keyboard and mouse buttons are simulated with Applications.docx
《用应用程序模拟键盘和鼠标按键Keyboard and mouse buttons are simulated with Applications.docx》由会员分享,可在线阅读,更多相关《用应用程序模拟键盘和鼠标按键Keyboard and mouse buttons are simulated with Applications.docx(12页珍藏版)》请在冰豆网上搜索。
用应用程序模拟键盘和鼠标按键KeyboardandmousebuttonsaresimulatedwithApplications
用应用程序模拟键盘和鼠标按键(KeyboardandmousebuttonsaresimulatedwithApplications)
Today,withthepopularityofWindows,thewindowsinterfaceprogramiswelcomedbythemajorityofusers.Therearenomorethantwooperationsfortheseprograms,keyboardinputcontrolandmouseinputcontrol.Sometimes,forcomplexorrepetitiveinputoperations,canweinsteadofmanualinputbyprogramminginsteadofusingaprogramtosimulatekeyboardandmouseinput?
Theanswerisyes.HeremainlythroughthetwoWindowsAPIfunctiontoachieve.Here'sanexampleofVC++toshowyouhowtoimplementthesetwofunctions.
Analogkeyboard,weusetheKeybd_eventAPIfunction,simulatethemousebutton,usingthemouse_eventfunction.CallingtheAPIfunctioninVCissimpleandconvenient.
First,let'sintroducetheKeybd_eventfunction.Keybd_eventcantriggerakeyevent,thatistosay,togenerateaWM_KEYDOWNorWM_KEYUPmessage.Ofcourse,youcanalsousethesetwomessagestosimulatekeystrokes,butnotdirectlywiththisfunction.Keybd_eventhasfourparameters,thefirstisthevirtualkeyvalueforthekey,suchastheEnterkeyvk_returnandthetabkeyvk_tab.Thesecondparameteristhescancode,generallynotset,with0insteadoflineparametersforthethirdoptionsign,ifKeydownissetto0,ifKeyupissetto"KEYEVENTF_KEYUP",thefourthparameterisgenerallysetto0.Thefollowingcodecanbeusedtosimulatethepresskey,wheretheXXrepresentsthevirtualkeyvalueoftheXXkey,andhereisthekeycodeforeachkey,suchas''A''=65
Keybd_event(65,0,0,0);
Keybd_event(65,0,KEYEVENTF_KEYUP,0);...
Thebestmouse_eventwithSetCursorPos(x,y)functionused,similartoKeybd_event,mouse_eventhasfiveparameters,thefirstoptiontosign,MOUSEEVENTF_LEFTDOWNsaidtheleftclickontheMOUSEEVENTF_LEFTUPbuttontoreleasesaid,thesystemsendsthecorrespondingmessage.Thetwoorthreeargumentsrepresentx,y,respectively
Therelativepositionisgenerallysetto0,0,andthefourorfiveparameterisnotimportant,andcanbegenerallysetto0,0.TogetmoredetailedusageoftheKeybd_eventandmouse_eventfunctions,refertoMSDNorDelphihelp.
Thefollowingisanexamplecodeformouse_event:
POINTlpPoint;
GetCursorPos(&lpPoint);
SetCursorPos(lpPoint.x,lpPoint.y);
Mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);
Mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);
Theabovecodeindicatesdoubleclickingofthemouse.Toindicateaclick,youcanusetwomouse_event(oncedownandonerelease).
Note,whetheritiskeyboardormouseevents,shouldpayattentiontorestore,thatis,pressthebuttontobereleased,aKeydowncorrespondstoaKeyup;clickthemouseshouldbereleased,oritmayaffectthefunctionoftheprogram.
Well,Ihopethisarticlewillletyouhaveapreliminaryunderstandingofthekeyboardandmousebuttons.Ifyouwanttoknowmoreaboutit,youcanconsulttheMSDNonlinehelp,anddoalotofhands-onwork.Itmaybeofgreathelptoyou
New:
Http:
//
WithVCanalogbuttons,thefirstthingIthinkofis,ofcourse,SendMessage,whichusesmessagestosendawindow
SendMessage(WM_KEYDOWN,'a',0L);
Thisbuttonisreallyenoughtosimulatenormalbuttons,butwhenyousimulatethefunctionbuttons,suchasnum,lock,andprintscreen,problemsarise,andthesimulationfails
Thistimeweneedtousethekeybd_eventfunction,thisfunctionisnottosendmessagestosimulatethekeyboard,andisdirectlysimulatedkeyboardpractice
Usecase
Keybd_event(VK_SNAPSHOT,0x45,KEYEVENTF_EXTENDEDKEY|0,0);
Usedtosimulateprintscreenbuttons
ThusfundamentallysolvestheproblemthatthosespecialfunctionkeyscannotbesimulatedbySendMessageorPostMessage
Usingapplicationstosimulatekeyboardandmousebuttons,id=255
Author:
Owen.Guo
Listofcommonlyusedkeyvalues:
Keycode
Constantvaluedescription
Vbkeylbutton1leftmousebutton
Vbkeyrbutton2rightmousebutton
Vbkeycancel3cancelkey
Vbkeymbutton4middlemousebutton
vbkeyback8退键
vbkeytab9标签键
vbkeyclear12明确键
vbkeyreturn13进入键
vbkeyshift16班键
vbkeycontrol17Ctrl键
18菜单键vbkeymenu
19键vbkeypause停顿
vbkeycapital20大写锁定键
27键vbkeyescapeESC
32键vbkeyspace空格键
33键vbkeypageupPageUp
vbkeypagedown键34下一页
vbkeyend35端键
vbkeyhome36家键
vbkeyleft37左箭头键
vbkeyup38箭键
vbkeyright39右箭头键
vbkeydown40向下箭头键
vbkeyselect41选择键
vbkeyprint42打印屏幕键
vbkeyexecute43执行键
vbkeysnapshot44拍摄键
vbkeyinser45英寸键
vbkeydelete46德尔键
vbkeyhelp47帮助键
144vbkeynumlockNumLock键
一个键到Z键与其ASCII码的相应值'a'到Z是一致的
常数值描述
65个键vbkeya
vbkeyb66B键
vbkeyc67C键
vbkeyd68d键
vbkeye69E键
vbkeyf70F键
vbkeyg71克键
vbkeyh72h键
73我键vbkeyi
74键vbkeyj[J].
vbkeyk75K键
vbkeyl76L键
vbkeym77米键
vbkeyn78N键
vbkeyo79O键
vbkeyp80P键
vbkeyq81问键
vbkeyr82R键
vbkeys83键
vbkeyt84T键
vbkeyu85U键
vbkeyv86V键
vbkeyw87W键
vbkeyx88x键
vbkeyy89Y键
vbkeyz90Z键
0键到9键与其ASCII码的相应值“0”“9”是一致的到
常数值描述
480键vbkey0
491键vbkey1
502键vbkey2
513键vbkey3
524键vbkey4
535键vbkey5
546键vbkey6
557键vbkey7
568键vbkey8
579键vbkey9
数字小键盘上的键
常数值描述
960键vbkeynumpad0
971键vbkeynumpad1
982键vbkeynumpad2
993键vbkeynumpad3
1004键vbkeynumpad4
1015键vbkeynumpad5
1026键vbkeynumpad6
1037键vbkeynumpad7
1048键vbkeynumpad8
1059键vbkeynumpad9
vbkeymultiply106乘号(*)键
vbkeyadd107加号(+)键
vbkeyseparator108进入键(在数字小键盘上)
vbkeysubtract109减号(-)键
vbkeydecimal110小数点键(。
)
vbkeydivide111除号(/)键
功能键
常数值描述
vbkeyf1112F1键
vbkeyf2113F2键
114键vbkeyf3F3
115键vbkeyf4F4
116键vbkeyf5F5
117键vbkeyf6F6
118键vbkeyf7F7
119键vbkeyf8F8
120键vbkeyf9F9
121键vbkeyf10F10
122键vbkeyf11F11
123键vbkeyf12F12
124键vbkeyf13F13
125键vbkeyf14F14
126键vbkeyf15F15
127键vbkeyf16F16
常数用法键位
可在代码中的任何地方用下列常数代替实际值:
常数值描述
vbkeylbutton0x1鼠标左键
vbkeyrbutton0x2鼠标右键
vbkeycancel0x3取消键
vbkeymbutton0x4鼠标中键
vbkeyback0x8Backspace键
vbkeytab0x9选项卡键
vbkeyclear0xc明确键
vbkeyreturn0xd进入键
vbkeyshift0x10移键
vbkeycontrol0x11Ctrl键
vbkeymenu0x12菜单(ALT)键
vbkeypause0x13暂停键
vbkeycapital0x14大写锁定键
vbkeyescape0x1BESC键
vbkeyspace0x20空格键
vbkeypageup0x21页键
下一页键vbkeypagedown0x22
vbkeyend0x23端键
vbkeyhome0x24家键
vbkeyleft0x25左箭头键
vbkeyup0x26箭头键
vbkeyright0x27的右箭头键
vbkeydown0x28向下箭头键
vbkeyselect0x29选择键
vbkeyprint0x2a打印屏幕键
vbkeyexecute0x2b执行键
vbkeysnapshot0x2c快照键
vbkeyinsert0x2d插入键
vbkeydelete0x2e删除键
vbkeyhelp0x2F帮助键
vbkeynumlock0x90NumLock键
一个至Z键与一杴Z字母的ASCII码相同:
常数值描述
65个键vbkeya
vbkeyb66B键
vbkeyc67C键
vbkeyd68d键
vbkeye69E键
vbkeyf70F键
vbkeyg71克键
vbkeyh72h键
73我键vbkeyi
74键vbkeyj[J].
vbkeyk75K键
vbkeyl76L键
vbkeym77米键
vbkeyn78N键
vbkeyo79O键
vbkeyp80P键
vbkeyq81问键
vbkeyr82R键
vbkeys83键
vbkeyt84T键
vbkeyu85U键
vbkeyv86V键
vbkeyw87W键
vbkeyx88x键
vbkeyy89Y键
vbkeyz90Z键
0909至键与数字杴的ASCII码相同:
常数值描述
480键vbkey0
491键vbkey1
502键vbkey2
513键vbkey3
524键vbkey4
535键vbkey5
546键vbkey6
557键vbkey7
568键vbkey8
579键vbkey9
下列常数代表数字键盘上的键:
常数值描述
0键vbkeynumpad00x60
vbkeynumpad10x611键
vbkeynumpad20x622键
vbkeynumpad30x633键
vbkeynumpad40x644键
vbkeynumpad50x655键
vbkeynumpad60x666键
vbkeynumpad70x677键
vbkeynumpad80x688键
vbkeynumpad90x699键
vbkeymultiply0x6a乘号(*)键
vbkeyadd0x6b加号(+)键
vbkeyseparator0x6c进入键
vbkeysubtract0x6d减号(杴)键
vbkeydecimal0x6e小数点(。
)键
vbkeydivide0x6f除号(/)键
下列常数代表功能键:
常数值描述
vbkeyf10x70F1键
vbkeyf20x71F2键
vbkeyf30x72F3键
vbkeyf40x73F4键
vbkeyf50x74F5键
vbkeyf60x75F6键
vbkeyf70x76F7键
vbkeyf80x77F8键
vbkeyf90x78F9键
vbkeyf100x79F10键
vbkeyf110x7aF11键
vbkeyf120x7BF12键
vbkeyf130x7cF13键
vbkeyf147d键F14
vbkeyf15F15键0×7e
vbkeyf160x7fF16键
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 用应用程序模拟键盘和鼠标按键Keyboard and mouse buttons are simulated with Applications 应用程序 模拟 键盘 鼠标 按键 Keyboard
链接地址:https://www.bdocx.com/doc/11284952.html