Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8202889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:21:07+00:00 2026-06-07T07:21:07+00:00

I have my barcode reader programmed to add a prefix and suffix of ,

  • 0

I have my barcode reader programmed to add a prefix and suffix of “,” and otherwise to work just like a keyboard. I have a Windows Form that will be open when barcodes are scanned.

Rather than writing a bunch of KeyDown code, Reactive Extensions seems perfect for this kind of work. What I’d like to do:

  • When a comma is pressed, start holding on to key presses (don’t let them be handled by any control on the screen)
  • Collect all keys until another comma is pressed or 250ms have gone by.
  • If no comma is pressed within 250ms, hand the key presses back to whatever control is active.
  • If comma is pressed, do processing on the string value scanned in from the barcode.

How can I use System.Reactive to hold key presses when matching a prefix and suffix for a barcode scanner, process if suffix is matched, but handle key presses normally when the suffix isn’t matched within a time limit?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T07:21:09+00:00Added an answer on June 7, 2026 at 7:21 am

    Someone will come along and probably give a more elegant answer than this. But I found this one challenging.

    First things first, this example does not show how to do it for keys on forms. There is sufficient additional complexity there that it bears trying yourself first, or asking another question. It would require a full application to answer all aspects of your question here. Suffice to say that:

    1. You can turn KeyEventArgs into an observable that could be used in this framework
    2. You can decide to suppress KeyEventArgs that make it into the barcode stream with SuppressKeyPress
    3. You can decide to not suppress any KeyEventArgs in the non-barcode stream

    The solution as it stands involves defining a function that takes an IObservable<char> and turns it into a GroupedObservable that marks (with a bool) whether the underlying char was inside a ‘barcode’ stream (true) or not (false):

    public IObservable<IGroupedObservable<bool, IObservable<char>>> GroupBySurroundingChars(IObservable<char> source, char ends, TimeSpan within)
    {
        var result = 
            source.Buffer(() => 
                source.Select(c => {
                    if (c == ends) return source.Where(x => x == ends).Amb(Observable.Timer(within).Select(_ => default(char)));
                    else           return Observable.Return(default(char));
                }).Concat())
                .GroupBy(buffer => buffer.Count > 2 && buffer[0] == ends && buffer.Last() == ends, buffer => buffer.ToObservable());                        
    
        return result;
    }
    

    What this function is doing is:

    1. Starting a buffer with every character
    2. If that character wasn’t a comma, return the buffer immediately
    3. If that character was a comma, hold the buffer open until another comma is found or 250ms have passed
    4. Check if the buffer contains commas at either end (mark as a barcode) or not (mark as no barcode)

    And then a full usage example:

    var keys1 = "xxx,1234567,xxx,1,xxx".ToCharArray().ToObservable(Scheduler.ThreadPool).Do(_ => Thread.Sleep(100)).Publish().RefCount();
    var keys2 = "xxx,1234567,xxx,1,xxx".ToCharArray().ToObservable(Scheduler.ThreadPool).Do(_ => Thread.Sleep(10)).Publish().RefCount();
    
    var result = GroupBySurroundingChars(keys1, ',', TimeSpan.FromMilliseconds(250));
    
    var barcodes = result.Where(x => x.Key);
    var others = result.Where(x => !x.Key);
    
    barcodes.Subscribe(groups => groups.Subscribe(x => x.ToList().Dump()));
    

    If you use keys1, the key presses are too slow to find the first barcode, but it finds the second. If you use keys2, the key presses are fast enough to find both barcodes.

    In either case, the others stream contains all keys that were not eventually marked as containing barcodes. The barcodes stream can be taken as a character by character stream, or converted into a List with each set of barcodes as I did above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form where users scan in a barcode, the barcode reader automatically
I have an array of bytes that has come from a barcode reader (connected
I have a form which I read data to textbox from a barcode reader.
I have a barcode scanner (which acts like a keyboard) and of course I
I have a barcode of the format 123456######## . That is, the first 6
I have an application that generates barcode in image format and it is read
i have an windows mobile application written in c# compact framework which use barcode
I have a crystal report that I have to add a Bar Code to.
I have a PDF file which contains just 1 Page. I have a barcode
Here is the function I have now that obviously doesn't work. The reason it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.