2017-01-03 17 views
-4

私はキーボードでUsb経由で接続するBarcodeScannerからキーを記録するために単純な接続を使用しています。キーボードが他のアプリケーションに書き込まれないようにする方法

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(); 
    } 

} 
} 

問題があり、バーコードスキャナがフォーカスされている方のアプリケーションへの書き込み:私は、私はオンラインで見つけるこの例を使用しています。このデバイスから実行中のすべてのデータをアプリケーションにリダイレクトすることは可能ですか?

+3

「私はそれに続いてグーグルに馬鹿だよね? –

+0

試してそれを救済するためにそれを編集しました –

答えて

0

デバイスがキーボード以外のHMIデバイスではなくキーボードとしてインストールされている場合、キーボードやマウスがOSによって制限されているため、特に簡単ではありません。

This answerは、この制限を回避する方法について説明しています。

幸運を祈る!

関連する問題