473,386 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Input Device Problems

I've got an application that takes input from a handheld scanner: Once the
incoming text meets the RegEx format and is the correct length, the command
is accepted.

The scanner that plugs in on the keyboard port.

The problem comes from the use of the default MessageBox whenever I need to
display information to the operator:

DialogResult dr =
MessageBox.Show("Do this?", Title,
MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
DefaultButton.Button1);

Sometimes, these scanners send in more data (usually blank spaces) after a
MessageBox is displayed, and (as some of you may know) the space bar can be
used to select the default button.

I would like to flush the scanner's buffer, effectively flushing the
keyboard buffer? Are p/invoke calls needed for this, or is there something in
the Framework?

I'm running 2.0 Framework with Visual Studio 2005 - but I'll take tips and
how-to info from just about anything.

Thanks,
~Joe
Oct 30 '08 #1
4 2433
On Thu, 30 Oct 2008 12:44:11 -0700, jp2msft
<jp*****@discussions.microsoft.comwrote:
[...]
Sometimes, these scanners send in more data (usually blank spaces) after
a
MessageBox is displayed, and (as some of you may know) the space bar can
be
used to select the default button.

I would like to flush the scanner's buffer, effectively flushing the
keyboard buffer? Are p/invoke calls needed for this, or is there
something in
the Framework?
How are you handling the input currently? Is there an existing form or
something that you're using to read the keyboard input?

I don't think that flushing the buffer is necessarily going to work,
depending on how the scanner itself behaves. But, if it _would_ work,
then it seems to me that you really should just not display the MessageBox
until the same code that reads the scanner input has itself consumed the
remainder of the data.

You may want to simply read until there's no data available, or read for
some specific amount of time (half a second or something like
that...enough to get all the data, but not so much that the user will feel
like there's some lag).

Note that if this approach wouldn't work, then flushing the buffer
wouldn't work either, because the only reason either won't work is the
same: data could come in after you think you're done reading it.

Another alternative is to create your own modal dialog rather than relying
on the MessageBox, and in that dialog handle keyboard input however you
like, ignoring a spacebar input if that's what you want to do.

Pete
Oct 30 '08 #2
Hi Pete,

Thanks for the fast response!

Yes: There is a form that is waiting on input. The problem is complicated by
the fact that both a scanner and the keyboard are allowed - just in case an
item is too dirty to be scanned, a scanner gets dropped/smashed, or any other
unforeseeable (sp?) mishap.

The keyboard requirement prevents implimenting a timer, and processing
starts once the RegEx expression is met.

Creating a custom modal form is a good idea. I did think of this myself, but
dismissed it, thinking that this was a more complicated solution than
learning how to use tools that were at my disposal.

Along that same line, now I am thinking about shifting the Focus to a
ReadOnly textbox as soon as the RegEx expression is met. This should allow
all of the remaining buffer characters to be consumed without anything in my
application trying to use them. It still sounds like a hack, though. :)

"Peter Duniho" wrote:
On Thu, 30 Oct 2008 12:44:11 -0700, jp2msft
How are you handling the input currently? Is there an existing form or
something that you're using to read the keyboard input?

I don't think that flushing the buffer is necessarily going to work,
depending on how the scanner itself behaves. But, if it _would_ work,
then it seems to me that you really should just not display the MessageBox
until the same code that reads the scanner input has itself consumed the
remainder of the data.

You may want to simply read until there's no data available, or read for
some specific amount of time (half a second or something like
that...enough to get all the data, but not so much that the user will feel
like there's some lag).

Note that if this approach wouldn't work, then flushing the buffer
wouldn't work either, because the only reason either won't work is the
same: data could come in after you think you're done reading it.

Another alternative is to create your own modal dialog rather than relying
on the MessageBox, and in that dialog handle keyboard input however you
like, ignoring a spacebar input if that's what you want to do.

Pete
Oct 30 '08 #3
On Thu, 30 Oct 2008 13:28:08 -0700, jp2msft
<jp*****@discussions.microsoft.comwrote:
Hi Pete,

Thanks for the fast response!

Yes: There is a form that is waiting on input. The problem is
complicated by
the fact that both a scanner and the keyboard are allowed - just in case
an
item is too dirty to be scanned, a scanner gets dropped/smashed, or any
other
unforeseeable (sp?) mishap.

The keyboard requirement prevents implimenting a timer, and processing
starts once the RegEx expression is met.
Why does the keyboard requirement prevent using a timer? All you'd be
trying to do is ensure you've consumed all of the input currently
available. Even if the user can type as fast as the scanner can send
input, it should be the same goal and thus same logic, and for mortal
human users, they are likely to simply enter the data you want them to and
then wait. A short timer won't even be noticeable to them.

As far as whether processing starts as soon as the RegEx expression is met
goes, well...you wrote this code, right? You have control over when
processing actually starts. Besides, as I understand it, processing
doesn't literally start as soon as the pattern is matched, because you
prompt the user for confirmation first. So all we're really talking about
here is a short delay before that confirmation dialog is presented.

Again, a half second delay (or whatever you decide is appropriate for the
purpose of consuming whatever data is left from the scanner) should be
perfectly fine.
Creating a custom modal form is a good idea. I did think of this myself,
but
dismissed it, thinking that this was a more complicated solution than
learning how to use tools that were at my disposal.
A modal form is practically the same in implementation as any other form.
If you've already coded a form that can take the input from the scanner,
then I think you already have the knowledge needed to do something similar
in a modal form.
Along that same line, now I am thinking about shifting the Focus to a
ReadOnly textbox as soon as the RegEx expression is met. This should
allow
all of the remaining buffer characters to be consumed without anything
in my
application trying to use them. It still sounds like a hack, though. :)
I don't understand the description. The problem, as I understand it, is
that the remaining input is processed by the modal MessageBox you
display. Unless you delay presentation of that MessageBox long enough for
the read-only TextBox to consume the remaining input, shifting the focus
won't help.

If you _do_ delay presentation of the MessageBox, then that's basically
just the timer-based solution I proposed earlier. Right?

Pete
Oct 30 '08 #4
Sometimes my head can be hard, and it is difficult to get a new idea or two
in there. But, this time I did it! ;)

I've got a timer checking the input. As it turned out, there was already a
timer on the form ticking every 200 ms, so I just added a text input checker
to that routine.

Thanks for being patient with an old, hard headed donkey!

"Peter Duniho" wrote:
Why does the keyboard requirement prevent using a timer? All you'd be
trying to do is ensure you've consumed all of the input currently
available. Even if the user can type as fast as the scanner can send
input, it should be the same goal and thus same logic, and for mortal
human users, they are likely to simply enter the data you want them to and
then wait. A short timer won't even be noticeable to them.

As far as whether processing starts as soon as the RegEx expression is met
goes, well...you wrote this code, right? You have control over when
processing actually starts. Besides, as I understand it, processing
doesn't literally start as soon as the pattern is matched, because you
prompt the user for confirmation first. So all we're really talking about
here is a short delay before that confirmation dialog is presented.

Again, a half second delay (or whatever you decide is appropriate for the
purpose of consuming whatever data is left from the scanner) should be
perfectly fine.
Oct 31 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: JustSomeGuy | last post by:
I need to log into a web page automatically. The web page has a password text field and a login button. (A form?) How do I simulate that a user logged in and entered the password and pressed...
7
by: Don Riesbeck Jr. | last post by:
I'm working on an application (OEM) using C# that utilizes input from a keyboard, and USB Barcode Scanner. The scanner is a HID Keyboard device, and input from it is sent to the system as if it...
8
by: Tony Liu | last post by:
I am having a "Null Device is Missing" compile error when compiling a c++ project. The documentation from MSDN said it could be caused by low system resource or the user account does not have...
1
by: Louis Cypher | last post by:
I'm working on an application (OEM) using c# that uses input from a keyboard and a USB Barcode Scanner. I need to be able to identify keystrokes from the barcode scanner and remove them from the...
3
by: =?Utf-8?B?cHJvZ2dlcg==?= | last post by:
I have a C# application that hosts an AxWebBrowser control which I automate by sending mouse clicks and keyboard input. I have had various problems in doing this due to a bug in the AxWebBrowser...
0
by: =?Utf-8?B?QmV2eV9KZXRlcg==?= | last post by:
Using XP Pro as an administrator. Experiencing 3 problems: 1) Device Manager is empty in both normal & safe modes, 2) F8 will not take me into Safe Mode but MSConfig will, & 3) Computer folder...
4
by: Newbie | last post by:
Hello I need to enter a string of the form abc (a string of characters followed by EOF) #include<stdio.h> #include<stdlib.h> #include<string.h> #define MAX 100 int main(void) {
4
by: JDS | last post by:
I have an application that interfaces with a USB device using the .Net serial port. The code works fine, displaying live data on the screen; that is until the USB lead is pulled out from the PC...
2
by: wizche | last post by:
Hi, I'm currently trying to develop a IR Remote (TV consumer) listener in C under Linux. First of all I tried with an old notebook with an integrated IR peripheral (FIR)under Debian (kernel...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.