C 模擬鍵盤事件

2021-06-23 03:16:50 字數 3586 閱讀 4595

c#模擬鍵盤事件

public partial class form1 : form

[dllimport("user32.dll")]

public static extern intptr findwindow(string lpclassname, string lpwindowname);  //匯入尋找windows窗體的方法

[dllimport("user32.dll")]

public static extern bool setforegroundwindow(intptr hwnd);  //匯入為windows窗體設定焦點的方法

[dllimport("user32.dll")]

public static extern void keybd_event(byte bvk, byte bscan, int dwflags, int dwextrainfo);  //匯入模擬鍵盤的方法

private void button1_click(object sender, eventargs e)

clipboard.settext("第三方");

setforegroundwindow(calculatorhandle);          

keybd_event(0x11, 0, 0, 0);

keybd_event(86, 0, 0, 0);

keybd_event(0x11, 0, 2, 0);

keybd_event(86, 0, 2, 0);}}

keybd_event方法的第乙個引數值有:(例如:keybd_event(0x11, 0, 0, 0)是ctrl 鍵 按下  keybd_event(0x11, 0, 2, 0)是ctrl 鍵 鬆開)

vbkeylbutton 0x1 滑鼠左鍵  

vbkeyrbutton 0x2 滑鼠右鍵  

vbkeycancel 0x3 cancel 鍵  

vbkeymbutton 0x4 滑鼠中鍵  

vbkeyback 0x8 backspace 鍵  

vbkeytab 0x9 tab 鍵  

vbkeyclear 0xc clear 鍵  

vbkeyreturn 0xd enter 鍵  

vbkeyshift 0x10 shift 鍵  

vbkeycontrol 0x11 ctrl 鍵  

vbkeymenu 0x12 menu 鍵   

vbkeypause 0x13 pause 鍵  

vbkeycapital 0x14 caps lock 鍵  

vbkeyescape 0x1b esc 鍵  

vbkeyspace 0x20 spacebar 鍵  

vbkeypageup 0x21 page up 鍵  

vbkeyend 0x23 end 鍵  

vbkeyhome 0x24 home 鍵  

vbkeyleft 0x25 left arrow 鍵  

vbkeyup 0x26 up arrow 鍵  

vbkeyright 0x27 right arrow 鍵  

vbkeydown 0x28 down arrow 鍵  

vbkeyselect 0x29 select 鍵  

vbkeyprint 0x2a print screen 鍵  

vbkeyexecute 0x2b execute 鍵  

vbkeysnapshot 0x2c snapshot 鍵  

vbkeydelete 0x2e delete 鍵  

vbkeyhelp 0x2f help 鍵  

vbkeynumlock 0x90 num lock 鍵  

vbkeya 65 a 鍵  

vbkeyb 66 b 鍵  

vbkeyc 67 c 鍵  

vbkeyd 68 d 鍵  

vbkeye 69 e 鍵  

vbkeyf 70 f 鍵  

vbkeyg 71 g 鍵  

vbkeyh 72 h 鍵  

vbkeyi 73 i 鍵  

vbkeyj 74 j 鍵  

vbkeyk 75 k 鍵  

vbkeyl 76 l 鍵  

vbkeym 77 m 鍵  

vbkeyn 78 n 鍵  

vbkeyo 79 o 鍵  

vbkeyp 80 p 鍵  

vbkeyq 81 q 鍵  

vbkeyr 82 r 鍵  

vbkeys 83 s 鍵  

vbkeyt 84 t 鍵  

vbkeyu 85 u 鍵  

vbkeyv 86 v 鍵  

vbkeyw 87 w 鍵  

vbkeyx 88 x 鍵  

vbkeyy 89 y 鍵  

vbkeyz 90 z 鍵  

vbkey0 48 0 鍵  

vbkey1 49 1 鍵  

vbkey2 50 2 鍵  

vbkey3 51 3 鍵  

vbkey4 52 4 鍵  

vbkey5 53 5 鍵  

vbkey6 54 6 鍵  

vbkey7 55 7 鍵  

vbkey8 56 8 鍵  

vbkey9 57 9 鍵  

vbkeynumpad0 0x60 0 鍵  

vbkeynumpad1 0x61 1 鍵  

vbkeynumpad2 0x62 2 鍵  

vbkeynumpad3 0x63 3 鍵  

vbkeynumpad4 0x64 4 鍵  

vbkeynumpad5 0x65 5 鍵  

vbkeynumpad6 0x66 6 鍵  

vbkeynumpad7 0x67 7 鍵  

vbkeynumpad8 0x68 8 鍵  

vbkeynumpad9 0x69 9 鍵  

vbkeymultiply 0x6a multiplicationsign(*)鍵  

vbkeyadd 0x6b plus sign (+) 鍵  

vbkeyseparator 0x6c enter 鍵   

vbkeysubtract 0x6d minus sign (-) 鍵  

vbkeydecimal 0x6e decimal point (.) 鍵  

vbkeydivide 0x6f division sign (/) 鍵  

vbkeyf1 0x70 f1 鍵  

vbkeyf2 0x71 f2 鍵  

vbkeyf3 0x72 f3 鍵  

vbkeyf4 0x73 f4 鍵  

vbkeyf5 0x74 f5 鍵  

vbkeyf6 0x75 f6 鍵  

vbkeyf7 0x76 f7 鍵  

vbkeyf8 0x77 f8 鍵  

vbkeyf9 0x78 f9 鍵  

vbkeyf10 0x79 f10 鍵  

vbkeyf11 0x7a f11 鍵  

vbkeyf12 0x7b f12 鍵 

C 模擬鍵盤滑鼠事件

1.模擬鍵盤事件 system.windows.forms.sendkeys 以下是 sendkeys 的一些特殊鍵 表。鍵 backspace 或 break caps lock del 或 delete 或 down arrow 下箭頭鍵 end enter 或 esc help home in...

模擬鍵盤事件與滑鼠事件

模擬事件 title head body button id mouseeventtrigger 鍵盤模擬按鈕事件 button button id keyboardeventtrigger 按鈕模擬鍵盤事件 button body script varbtn1 document.getelemen...

selenium之模擬鍵盤事件

selenium裡面提供了乙個keys 類,它提供了鍵盤上幾乎所有的按鍵方法 from selenium.webdriver.common.keys import keys 匯入keys類 示例 from selenium import webdriver from selenium.webdriv...