none
KeyDown event not being triggered by scanner RRS feed

  • Question

  • I have winforms application (C#), for which it is possible to use a barcode scanner as an imput for. I'm not doing any fancy POS functionality here with the scanner - just using it as a keyboard wedge kind of input.

    The way it works is:

    • I tell my users to program their scanners so every scan is prefixed with a tilde (~) character, and ends with a tab.
    • The forms which use the barcode scanner as an input are set up to listen to the KeyDown event. As soon as they register the tilde character (e.KeyCode == Keys.Oemtilde), it changes focus to the barcode field on the form (while suppressing the output of the tilde character)
    • Normal functionality reads the barcode, and does what it needs to do.

    For the most part, this works fine.

    I have to users (different sites), who both have the exact same model barcode scanner (Motorola LS 2208). One (user 1) has set up his scanner as I suggested, and is working fine. User 1 (with the working scanner) has exported his settings, and given them to the other user (User 2), who imported it (Not sure how - through some software that comes with the scanner?).

    It seems like it should work for user 2. When he scans into notepad, the tilde character is first, and it sends a tab at the end.

    But when he uses in my application, it does not work right. The tilde character is not suppressed, and the user is not taken to the barcode field.

    After adding some debugging code to the app (It is a remote site - I cant get my hands on the scanner), I have found that the barcode scanner is not firing the KeyDown event.

    Now I'm wondering what would cause this. Why would the KeyDown event not be firing correctly, from a barcode scanner? Is there some setting on it or something that can change this?

    Any suggestions are appreciated.

    Thanks.

    Saturday, December 22, 2012 6:28 AM

All replies

  • If the user is doing everything by the book (your instructions) and it does not fire the KeyDown event my guess is this is something in their environment anything from OS service packs to something running that is conflicting with your app on the one computer.

    The easy things to do are match up OS and service packs, check versioning of barcode scanner. I mention this because sometime ago we ran into a similar issue with a 2D scanner and it was that on the computer not behaving as it should there were mismatch between that computer and the ones working in regards to drivers for the scanner.


    KSG

    Saturday, December 22, 2012 12:05 PM
    Moderator
  • If the user is doing everything by the book (your instructions) and it does not fire the KeyDown event my guess is this is something in their environment anything from OS service packs to something running that is conflicting with your app on the one computer.

    The easy things to do are match up OS and service packs, check versioning of barcode scanner. I mention this because sometime ago we ran into a similar issue with a 2D scanner and it was that on the computer not behaving as it should there were mismatch between that computer and the ones working in regards to drivers for the scanner.


    KSG

    Thanks KSG. I'll look into that.

    A little more information (Just been talking to the user who has it working).

    • Neither of the "Motorola LS 2208" scanners work on one of the user 2's machine.
    • The Motorola scanners work on another machine there. (user 2's site)
    • Another generic scanner works fine on the problem machine.
    • The problem machine is a windows 7 64 bit machine.

    User 1 is going to try it on a windows 7 64 bit machine (he usually runs it on a 32 bit machine). It could be a scanner/operating system issue.

    Sunday, December 23, 2012 10:51 AM
  • Hi fweeee,

    Any update to this issue?
    How can you let KeyDown event fired by scanner?

    Does the event fired if you press the key from keyboard or simulate key press?

    Best Regards,


    Bob Wu
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, December 27, 2012 9:16 AM
    Moderator
  • Hi fweeee,

    Any update to this issue?
    How can you let KeyDown event fired by scanner?

    Does the event fired if you press the key from keyboard or simulate key press?

    Best Regards,


    Bob Wu
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Bob,

    I'm still trying to sort this out. My user with the working scanner (or rather, scanner that works on his machines) has now tried the scanner on two other windows 7 64 bit machines, and both of them work fine. So it really looks like it is just this one machine.

    I'll need to get verification that an actual keystroke has the right effect - Christmas has slowed down my investigations somewhat.

    Thursday, December 27, 2012 11:35 AM
  • fweeee,

    do the machines on both sites have the same regional settings set in windows? or framework installed???

    just a shot in the dark...

    Noob

    Thursday, December 27, 2012 3:08 PM
  • use PreviewTextInput event instead.

    http://stackoverflow.com/questions/1495092/convert-received-keys-in-previewkeydown-to-a-string

    That the .NET framework returns the raw scan codes on KeyUp/KeyDown events is simply "impossible" (as in "too shocking to be true"). So what do we do? Use the PreviewTextInput event instead. We get the string representation of the key pressed like this: void KeyboardNavigation(object sender, TextCompositionEventArgs e) { string typedChar = e.Text; }

    Saturday, June 11, 2016 12:23 PM