RFID Reader Interface User's Guide
2.3 Extending the Reach
2.3.8
Make it fun: Working keys
Finally, let's get back to the trigger keys – remember your RFxxxM device has plenty of it, on
the left on the right, a big one on top and a pistol grip trigger (if you have a device equipped
with a barcode unit).
Capturing keyboard input as such is easy: We only have to add an event handler to the main
form's keydown event. And since we want to know when the key is released again we also
add an event handler to the keyup event. The simple code is shown below.
...
// Main Form initialization code
this.KeyDown += new System.Windows.Forms.KeyEventHandler(
this.KeyUp += new System.Windows.Forms.KeyUpHandler(
...
However, this code will only work as long as the main form has the focus. Whenever a
control residing on this main form has the focus, we will not get the key events. Therefore,
our demo application uses a simply 'intercept all controls' mechanism starting at the main
form. The main form's constructor invokes CaptureKeys(this).
protected void CaptureKeys(Control control)
{
for (int i = control.Controls.Count - 1; i >= 0; i--)
{
}
}
Now, we only have to check for the right keycode and invoke the correct trigger function.
36
this.KeyDownHandler);
this.KeyDownHandler);
Control c = control.Controls[i] as Control;
if (c != null)
{
c.KeyDown += new System.Windows.Forms.KeyEventHandler(
c.KeyUp += new System.Windows.Forms.KeyEventHandler(
CaptureKeys(c);
}
this.KeyDownHandler);
this.KeyUpHandler);
Function Manual, 12/2010, J31069-D0198-U001-A2-7618
Mobile Readers