-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();
}
}
}
的問題是,條形碼掃描器寫入任何應用程序處於焦點。運行時,是否可以將此設備的所有數據重定向到我的應用程序?
'我是愚蠢的谷歌後它'什麼? –
編輯它試圖挽救它 –