11

I am creating a p.o.s application for a cafeteria company in which the cashier scans his employee ID and it shows his information for the transaction.

My Problem is, the cashier can also use their keyboard for their input (employee ID) which is very risky.

if employee(true)
   show employee information
   then add orders
else
   Exception

Currently I just hide TexTbox from the UI, click New Button then set cursor focus on it. Then cashier scans employee id. In this part, the cashier can also type via keyboard and continue transaction.

What is the best way to handle this scenario? The rule is only barcode scanner must be use.

Thanks in regards

7
  • 3
    What's the question? How is detecting that the input is from the keyboard going to help you? Are you just going to throw away any keyboard input? What if the barcode scanner is broken, or the barcode on the customer's card is not readable? Wouldn't it be better if they could enter the number manually with the keyboard? This problem isn't software-related; it's a human situation. Teach the employees not to use the keyboard, except in case of emergency. Commented Feb 23, 2011 at 8:10
  • Yup your right..i am thinking other ways to make the app more secure... Commented Feb 23, 2011 at 8:22
  • If you're trying to make it impossible, I'm not sure what's wrong with hiding the textbox. They can't type into a hidden textbox. If you don't want to make it impossible, I'm not sure what else you'd do for security. I can't imagine this is a real security concern. Pop up a picture verification if you really think employees are going to be stealing each other's meal tickets. (I don't understand the edits you made to your question at all.) Commented Feb 23, 2011 at 8:31
  • I already did Employee Information verification..Ahmed Suggestion is right...Thanks Commented Feb 27, 2011 at 23:20
  • 1
    A common scenario is that a barcode won't scan, and the employee must manually key in the ID. I see that a lot at the grocery checkout. Scanners break, too. Finally, this means you'll need a working scanner for UI testing. Commented Feb 27, 2011 at 23:45

3 Answers 3

18

You could monitor the time it took for the code to be entered. A reader would enter the code much faster than a human typing it in.

Sign up to request clarification or add additional context in comments.

2 Comments

Ctrl+c / ctrl+v breaks that logic
@EricWu that can be solved trivially
15

If you have the possibility to modify the scanner configuration you can add some prefix/suffix to the scanned data. Then in the code you can detect those added characters.

If you can't, then only way is Ahmed's - measuring the time of data entry.

Comments

15

It is relatively easy done with RAW Input API.

Take a look at "Distinguishing Barcode Scanners from the Keyboard in WinForms"

I have a program that reads 3 different USB scanners and redirects the input to 3 different "channels" for processing. The code is somewhat extensive, so I am not postin it here. If you wish, I can paste some chunks of it or send you the project in e-mail.

As a clue are the imports:

#region Raw Input API

[DllImport( "User32.dll" )]
extern static uint GetRawInputDeviceList( IntPtr pRawInputDeviceList, ref uint uiNumDevices, uint cbSize );

[DllImport( "User32.dll" )]
extern static uint GetRawInputDeviceInfo( IntPtr hDevice, uint uiCommand, IntPtr pData, ref uint pcbSize );

[DllImport( "User32.dll" )]
extern static bool RegisterRawInputDevices( RAWINPUTDEVICE[ ] pRawInputDevice, uint uiNumDevices, uint cbSize );

[DllImport( "User32.dll" )]
extern static uint GetRawInputData( IntPtr hRawInput, uint uiCommand, IntPtr pData, ref uint pcbSize, uint cbSizeHeader );

#endregion

After you add the InputDevice to your project, you can listen to events by:

// Create a new InputDevice object and register InputDevice KeyPressed event handler.
input_dev = new InputDevice( Handle );
input_dev.KeyPressed += new InputDevice.DeviceEventHandler( m_KeyPressed );

The event handler m_KeyPressed lets you to distinguish your devices through e.Keyboard.SubClass

private void m_KeyPressed( object sender, InputDevice.KeyControlEventArgs e )
{
    // e.Keyboard.SubClass tells you where from the event came.
    // e.Keyboard.key gives you the input data.
}

Hope to have helped.

10 Comments

What's the InputDevice class and what kind of handle are you passing to the constructor?
Could you provide the full code please? the website can't open now.
It is still available in the web archive: web.archive.org/web/20150316093927/http://…
I know it was long time ago, but maybe do you still have this project alive?
web.archive.org/web/20130625064315/http://… this link works. Just need to go further back.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.