key kk
=new key(); // IntPtr a = new IntPtr(); kk.sendwinio(); kk.MykeyDown((int)key.VirtualKeys.VK_F1); System.Threading.Thread.Sleep(2000); kk.MykeyUp((int)key.VirtualKeys.VK_F1); 这是模拟键盘的调用方式
using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; using System.Diagnostics; using System.Management; namespace sendkey ...{
publicclass key ...{
constuint PROCESS_ALL_ACCESS =0x001F0FFF; constuint KEYEVENTF_EXTENDEDKEY =0x1; constuint KEYEVENTF_KEYUP =0x2; privatereadonlyint MOUSEEVENTF_LEFTDOWN =0x2; privatereadonlyint MOUSEEVENTF_LEFTUP =0x4; constuint KBC_KEY_CMD =0x64; constuint KBC_KEY_DATA =0x60; //得到窗体句柄的函数,FindWindow函数用来返回符合指定的类名( ClassName )和窗口名( WindowTitle )的窗口句柄 [DllImport("user32.dll", CharSet = CharSet.Auto)] publicstaticextern IntPtr FindWindow( string lpClassName, // pointer to class name string lpWindowName // pointer to window name ); [DllImport("user32.dll")] privatestaticexternint GetWindowThreadProcessId(IntPtr id,int pid);