-4
我正在使用简单的Hookup记录BarcodeScanner中的键,这是通过USB作为键盘进行连接的键。我使用的这个例子,我在网上找到:如何防止键盘写入其他应用程序
using System.Windows.Forms;
namespace RawInput
{
public partial class Form1 : Form
{
InputDevice id;
int NumberOfKeyboards;
public Form1()
{
InitializeComponent();
// Create a new InputDevice object, get the number of
// keyboards, and register the method which will handle the
// InputDevice KeyPressed event
id = new InputDevice(Handle);
NumberOfKeyboards = id.EnumerateDevices();
id.KeyPressed += new InputDevice.DeviceEventHandler(m_KeyPressed);
}
// The WndProc is overridden to allow InputDevice to intercept
// messages to the window and thus catch WM_INPUT messages
protected override void WndProc(ref Message message)
{
if(id != null)
{
id.ProcessMessage(message);
}
base.WndProc(ref message);
}
private void m_KeyPressed(object sender, InputDevice.KeyControlEventArgs e)
{
//Replace() is just a cosmetic fix to stop ampersands turning into underlines
lbHandle.Text = e.Keyboard.deviceHandle.ToString();
lbType.Text = e.Keyboard.deviceType;
lbName.Text = e.Keyboard.deviceName.Replace("&", "&&");
lbDescription.Text = e.Keyboard.Name;
lbKey.Text = e.Keyboard.key.ToString();
lbNumKeyboards.Text = NumberOfKeyboards.ToString();
lbVKey.Text = e.Keyboard.vKey;
}
private void btnClose_Click(object sender, System.EventArgs e)
{
this.Close();
}
}
}
的问题是,条形码扫描器写入任何应用程序处于焦点。运行时,是否可以将此设备的所有数据重定向到我的应用程序?
'我是愚蠢的谷歌后它'什么? –
编辑它试图挽救它 –