2011-02-23 101 views
6

我現在正在爲公司自助餐廳創建p.o.s應用程序,其中 收銀員掃描員工ID並顯示其交易信息。如何檢查用戶輸入是否來自條碼掃描儀或鍵盤?

我的問題是收銀員也可以使用他們的鍵盤輸入(Employeeid),這是非常危險的。

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

Currently i just hide textbox to the UI.. 
click New Button then cusror focus on it. 
then cashier scans employeeid. <---------------in this part(The cashier can also type via keyboard) and continue transaction. 

處理這種情況的最佳方法是什麼?規則只有條碼掃描儀必須使用。

謝謝您的問候

+3

什麼問題?如何檢測來自鍵盤的輸入是否會幫助您?你只是要扔掉任何鍵盤輸入?如果條碼掃描器損壞或客戶卡上的條形碼不可讀?如果他們可以用鍵盤手動輸入數字不是更好嗎?這個問題不是軟件相關的;這是人類的情況。教員工不要使用鍵盤,除非發生緊急情況。 – 2011-02-23 08:10:06

+0

是的你的權利..我正在想其他的方式來使應用程序更安全... – Crimsonland 2011-02-23 08:22:39

+0

如果你想讓它變得不可能,我不知道隱藏文本框有什麼問題。他們無法輸入隱藏文本框。如果你不想讓它變得不可能,我不確定你會爲安全做些什麼。我無法想象這是一個真正的安全問題。如果你真的認爲員工會偷吃對方的餐券,請出示圖片確認。 (我不明白你對你提出的問題所作的編輯*) – 2011-02-23 08:31:53

回答

13

您可以監視輸入代碼的時間。讀者輸入代碼要比輸入代碼快得多。

+0

不錯的理想,你可以執行更多關於代碼... – kemdo 2016-07-01 08:40:53

+6

Ctrl + c/ctrl + v打破邏輯 – 2016-08-01 18:38:23

+0

好點,你可以監聽關鍵事件來處理它。 – 2016-08-15 15:08:56

11

如果您可以修改掃描儀配置,則可以爲掃描的數據添加一些前綴/後綴。然後在代碼中可以檢測到添加的字符。

如果你不能,那麼唯一的辦法就是艾哈邁德 - 測量數據輸入的時間。

10

使用RAW Input API比較容易。

看看「Distinguishing Barcode Scanners from the Keyboard in WinForms

我有一個程序,讀取3個不同的USB掃描器和重定向輸入到3個不同的「信道」進行處理。代碼有點廣泛,所以我不在這裏發佈。 如果您願意,我可以粘貼它的一些塊或通過電子郵件發送給您項目。

爲線索是進口:

#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 

您添加InputDevice到項目後,您可以通過監聽事件:

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

事件處理m_KeyPressed可以讓你分辨你設備通過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. 
} 

希望能有所幫助。

+2

什麼是InputDevice類,以及傳遞給構造函數的是哪種類型的句柄? – 0xbadf00d 2011-03-10 17:56:08

+0

你能提供完整的代碼嗎?該網站現在無法打開。 – qakmak 2016-03-07 08:42:09

+3

它仍然可以在網絡存檔中找到:http://web.archive.org/web/20150316093927/http://nicholas.piasecki.name/blog/2009/02/distinguishing-barcode-scanners-from-the- keyboard-in-winforms – Alex 2016-07-28 08:53:19

相關問題