The following forum(s) have migrated to Microsoft Q&A (Preview): Developing Universal Windows apps!
Visit Microsoft Q&A (Preview) to post new questions.

Learn More

 locked
[UWP] How to identify if user input is from barcode scanner RRS feed

  • Question

  • Good Day,

    How to Identify if the user input from AutoSuggestBox is from barcode scanner?
    What I need is delete the query text after scanning , but when just manually input from keyboard , it will not.

    Thanks,
    NicoTing
    • Edited by NicoTing Tuesday, July 11, 2017 7:52 AM
    Monday, July 10, 2017 1:43 AM

All replies

  • A barcode scanner is usually registered as a keyboard. Difference with a normal keyboard is that usually no human type that fast. 


    Visual C++ MVP

    Monday, July 10, 2017 2:06 PM
  • Hi NicoTing,

    Could you please explain why do you want to identity various user input?


    I build UWPs: Arrnage Pro, Cloud Resource Tools

    Monday, July 10, 2017 8:04 PM
  • Hi NicoTing,

    Could you please explain why do you want to identity various user input?


    I build UWPs: Arrnage Pro, Cloud Resource Tools

    uhhm cause when the user search for an item using scanner , the text should be deleted so so when the user scan an item again , the previous text will not affect the item scan.
    Tuesday, July 11, 2017 12:41 AM
  • Ahaa, that makes sense.

    Some of the scanners will invoke an 'enter' at the end of the input (may needs settings, refer the manual), although we won't know if the enter is hit by keyboard or scanner, we can program it like:

    Whenever there's an enter, invoke the search, get the result and then clear the search box.

    Does that make sense?



    I build UWPs: Arrnage Pro, Cloud Resource Tools

    Tuesday, July 11, 2017 12:58 AM
  • Ahaa, that makes sense.

    Some of the scanners will invoke an 'enter' at the end of the input (may needs settings, refer the manual), although we won't know if the enter is hit by keyboard or scanner, we can program it like:

    Whenever there's an enter, invoke the search, get the result and then clear the search box.

    Does that make sense?



    I build UWPs: Arrnage Pro, Cloud Resource Tools

    haha can you please provide code?
    Thanks

    Tuesday, July 11, 2017 3:48 AM
  • Hi NicoTing,
    If you are open to accept this method, there are plenty posts on detecting enter key, for example:

    How to detect when enter key pressed


    If you still needs help with writing code, please provide the following info:

    1. What is your project type? WinForm? WPF? UWP? ASP.NET?

    2. Code snippet that you current use for handling user input.

    Basically, we need to understanding your pick of the implementations. Code for projects use MVVM will be way different than code uses event handlers in WPF and so on so forth.


    I build UWPs: Arrnage Pro, Cloud Resource Tools

    Tuesday, July 11, 2017 4:50 AM
  • Ok , I will try that


    • Edited by NicoTing Tuesday, July 11, 2017 5:08 AM
    Tuesday, July 11, 2017 5:00 AM
  • @ Saar

    But when i just input text and hit enter , that will delete the text too. I just need it to be deleted when barcode scanner is used
    Tuesday, July 11, 2017 5:13 AM
  • @NicoTing,

    That is right, that is the compromise I state earlier:

    -

     although we won't know if the enter is hit by keyboard or scanner,

    -

    That said, there still are ways to make it, maybe, better, for example, count the length of the text, if the length of the text equals the length expected, plus enter, we clear the text.

    The flaw would then be user type in full text and then enter and that will be cleared too. Now the question is, is that behavior acceptable?

    Note, all these thinking are based on we couldn't determine the input from keyboard or scanner.


    I build UWPs: Arrnage Pro, Cloud Resource Tools

    Tuesday, July 11, 2017 4:39 PM
  • @Nicoting,

    If you are writing a UWP application for reading date from a barcode scanner you have two options.

    1. Barcode Scanner configured as a keyboard

    2. Barcode Scanner configured as a HID POS Scanner and your app uses Windows.Devices.PointOfService.BarcodeScanner scenario APIs.

    With the latter, the data from the barcode scanner is raised as a data even to the BarcodeScanner API and this alone uniquely identifies the data as coming from the barcode scanner.

    In the case of a barcode scanner configured as a keyboard, you should be able to configure your scanner with a prefix that will differentiate it from data coming from the keyboard.  When you see the prefix you would treat the input as scanned data.

    Terry Warwick
    Microsoft

    Saturday, July 15, 2017 4:36 PM