读书人

怎么发送小键盘的1.不是数字键1

发布时间: 2011-12-18 22:54:38 作者: rapoo

如何发送小键盘的1.不是数字键1
我在自己做一个换键的程序.玩游戏的时候可以改 <快捷键>

这个是我的代码

namespace testKey
{
public partial class Form1 : Form
{
public Form1 ()
{
InitializeComponent ();
RegisterHotKey ( Handle, 100, 0, Keys.Q );
}


[DllImport ( "user32.dll " )]
public static extern bool RegisterHotKey ( IntPtr hWnd,
int id, uint fsModifiers, Keys vk );

[System.Runtime.InteropServices.DllImport ( "user32.dll " )]
public static extern bool UnregisterHotKey ( IntPtr hWnd, int id );

public enum KeyModifiers
{
None = 0,
Alt = 1,
Control = 2,
Shift = 4,
Windows = 8
}

protected override void WndProc ( ref Message m )
{
const int WM_HOTKEY = 0x0312;
switch (m.Msg)
{
case WM_HOTKEY:
ProcessHotkey ( m );
break;
}
base.WndProc ( ref m );


}

private void ProcessHotkey ( Message m )
{
IntPtr id = m.WParam;
string sid = id.ToString ();
switch (sid)
{
case "100 ":
//在此发送Num1... 请问如何实现.
//SendKeys.Send ( "1 " ); 1能发送..但不是小键盘的1
break;
}
}

[解决办法]
嗯...
貌似SendKeys没提供相应的方法;
Pinvoke keybd_event吧~
[解决办法]
keybd_event是WinSDK提供的一条发送键盘操作的函数.
可以模拟所有的键盘动作.具体说明去参考MSDN吧.

至于PInvoke,就是平台调用咯~
[解决办法]
GetKeyboardStatus
GetKeyboardState

读书人网 >C#

热点推荐