473,398 Members | 2,165 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,398 software developers and data experts.

KeyPress problem in VB.NET - any ideas welcome

Hi,

I am trying to capture data from magnetic stripe reader which is connected
via keyboard interface (therefore indistinguishable from normal keyboard
input). Basically, I am doing the following (in the Form.Keypress event
handler):

strCardData &= e.KeyChar
e.Handled = True

As you can see, I capture the input from the reader, and then prevent the
active control from receiving keyboard data. However, some characters get
lost, that is KeyPress event is not fired for all "keystrokes". It appears
to be random, but every time at least one character is lost. I figured that
one of the controls on the form is causing this, but after I removed ALL the
controls the problem still persists.

However, if I display another form modally, the same procedure works like a
charm there.

Like I said, any ideas are welcome, since I cannot even imagine what could
prevent the triggering of KeyPress event. Alternatively, perhaps someone
could suggest a different method of capturing keyboard data.

Thanks,

Niksa
Nov 20 '05 #1
6 4464
On Sun, 30 Nov 2003 15:59:49 +0100, "Niksa Baldun"
<di***********@du.htnet.hr> wrote:
Hi,

I am trying to capture data from magnetic stripe reader which is connected
via keyboard interface (therefore indistinguishable from normal keyboard
input). Basically, I am doing the following (in the Form.Keypress event
handler):

strCardData &= e.KeyChar
e.Handled = True

As you can see, I capture the input from the reader, and then prevent the
active control from receiving keyboard data. However, some characters get
lost, that is KeyPress event is not fired for all "keystrokes". It appears
to be random, but every time at least one character is lost. I figured that
one of the controls on the form is causing this, but after I removed ALL the
controls the problem still persists.

However, if I display another form modally, the same procedure works like a
charm there.

Like I said, any ideas are welcome, since I cannot even imagine what could
prevent the triggering of KeyPress event. Alternatively, perhaps someone
could suggest a different method of capturing keyboard data.

Thanks,

Niksa


I'm not sure if this is related to your problem, but some keys affect
focus - so the current control/form will change (and therefore the
event will be sent elsewhere). You can change this behaviour by
changing the control type to specify you want to hear all key presses.

Here's some C# cut out of one of my programs, you will immediately see
how to change it to VB.NET. I wrote this so I could handle cursor key
events on a user control, but it'll work for anything:

protected override void WndProc(ref System.Windows.Forms.Message m)
{
if( m.Msg == 0x87 )
{
m.Result = (IntPtr) 4; // DLGC_WANTALLKEYS
}
else
{
base.WndProc( ref m );
}
}

Probably not the answer to your problem, but it may prove useful.

Rgds,
Nov 20 '05 #2
No, didn't help.

I considered that focus my be shifted somehow, but it is not caused by input
from the reader - it is just regular alphanumeric data.

Just to make sure, please see if I converted your proc to VB correctly:

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = &H87 Then
m.Result = New IntPtr(4) 'DLGC_WANTALLKEYS
Else
MyBase.WndProc(m)
End If
End Sub

Thanks

"_Andy_" <wi******@nospamthanks.gov> wrote in message
news:pa********************************@4ax.com...
On Sun, 30 Nov 2003 15:59:49 +0100, "Niksa Baldun"
<di***********@du.htnet.hr> wrote:
Hi,

I am trying to capture data from magnetic stripe reader which is connectedvia keyboard interface (therefore indistinguishable from normal keyboard
input). Basically, I am doing the following (in the Form.Keypress event
handler):

strCardData &= e.KeyChar
e.Handled = True

As you can see, I capture the input from the reader, and then prevent the
active control from receiving keyboard data. However, some characters get
lost, that is KeyPress event is not fired for all "keystrokes". It appearsto be random, but every time at least one character is lost. I figured thatone of the controls on the form is causing this, but after I removed ALL thecontrols the problem still persists.

However, if I display another form modally, the same procedure works like acharm there.

Like I said, any ideas are welcome, since I cannot even imagine what couldprevent the triggering of KeyPress event. Alternatively, perhaps someone
could suggest a different method of capturing keyboard data.

Thanks,

Niksa


I'm not sure if this is related to your problem, but some keys affect
focus - so the current control/form will change (and therefore the
event will be sent elsewhere). You can change this behaviour by
changing the control type to specify you want to hear all key presses.

Here's some C# cut out of one of my programs, you will immediately see
how to change it to VB.NET. I wrote this so I could handle cursor key
events on a user control, but it'll work for anything:

protected override void WndProc(ref System.Windows.Forms.Message m)
{
if( m.Msg == 0x87 )
{
m.Result = (IntPtr) 4; // DLGC_WANTALLKEYS
}
else
{
base.WndProc( ref m );
}
}

Probably not the answer to your problem, but it may prove useful.

Rgds,

Nov 20 '05 #3
On Mon, 1 Dec 2003 09:03:09 +0100, "Niksa Baldun"
<di***********@du.htnet.hr> wrote:
No, didn't help.

I considered that focus my be shifted somehow, but it is not caused by input
from the reader - it is just regular alphanumeric data.

Just to make sure, please see if I converted your proc to VB correctly:

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = &H87 Then
m.Result = New IntPtr(4) 'DLGC_WANTALLKEYS
Else
MyBase.WndProc(m)
End If
End Sub

Thanks


That's the right conversion - it caters for when the framework filters
out certain key presses.

Do you get the right sequence in KeyDown/KeyUp? If you're certain the
barcode data is alphanumeric (and normally has a CRLF at the end),
then I'm at a bit of a loss. Perhaps the driver for the reader is
opening a window somewhere that might affect focus? Spyxx might be
useful...

As a quick test. Put a textbox onto the form with a default button
("OK"). Set focus to the textbox and then scan the barcode. Does that
work?

Rgds,

Nov 20 '05 #4
Hi,

I have tried putting the textbox on the form, but the result is the same -
some characters don't make it to the textbox. BUT if I comment out the
KeyPress event handler, everything works fine. As long as the event handler
exists, even if there is no code in it, and even if KeyPreview is set to
False, the error persists. But it is also interesting that, in a modal form
with only a command button on it, the error never appears.

Therefore I can only assume this is some kind of a bug in .NET framework,
unfortunately the one I can't find the workaround for. I will try and see if
there are any patches available - perhaps the issue has been resolved.

Anyway, thanks for taking the interest in my problem.
Niksa
"_Andy_" <wi******@nospamthanks.gov> wrote in message
news:90********************************@4ax.com...
On Mon, 1 Dec 2003 09:03:09 +0100, "Niksa Baldun"
<di***********@du.htnet.hr> wrote:
No, didn't help.

I considered that focus my be shifted somehow, but it is not caused by inputfrom the reader - it is just regular alphanumeric data.

Just to make sure, please see if I converted your proc to VB correctly:

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = &H87 Then
m.Result = New IntPtr(4) 'DLGC_WANTALLKEYS
Else
MyBase.WndProc(m)
End If
End Sub

Thanks


That's the right conversion - it caters for when the framework filters
out certain key presses.

Do you get the right sequence in KeyDown/KeyUp? If you're certain the
barcode data is alphanumeric (and normally has a CRLF at the end),
then I'm at a bit of a loss. Perhaps the driver for the reader is
opening a window somewhere that might affect focus? Spyxx might be
useful...

As a quick test. Put a textbox onto the form with a default button
("OK"). Set focus to the textbox and then scan the barcode. Does that
work?

Rgds,

Nov 20 '05 #5
Yes, Keypress and all keyinput events are buggy, in Framework 1.1 at least.

We have a larger app where the enter key stops working sooner or later (it
happens app wide, only restart will fix it..), instead the last button used
get's clicked. (in my case i've teached the user to use cltr-enter instead
that seems to work all the time..)
But barcode readers work flawless in my application, both in modal and
modaless screens.
I let them scan to a text field though, with tab as last char, and then I
trap the input on normal validate event.

- Fredrik

"Niksa Baldun" <di***********@du.htnet.hr> wrote in message
news:u4*************@tk2msftngp13.phx.gbl...
Hi,

I have tried putting the textbox on the form, but the result is the same -
some characters don't make it to the textbox. BUT if I comment out the
KeyPress event handler, everything works fine. As long as the event handler exists, even if there is no code in it, and even if KeyPreview is set to
False, the error persists. But it is also interesting that, in a modal form with only a command button on it, the error never appears.

Therefore I can only assume this is some kind of a bug in .NET framework,
unfortunately the one I can't find the workaround for. I will try and see if there are any patches available - perhaps the issue has been resolved.

Anyway, thanks for taking the interest in my problem.
Niksa
"_Andy_" <wi******@nospamthanks.gov> wrote in message
news:90********************************@4ax.com...
On Mon, 1 Dec 2003 09:03:09 +0100, "Niksa Baldun"
<di***********@du.htnet.hr> wrote:
No, didn't help.

I considered that focus my be shifted somehow, but it is not caused by inputfrom the reader - it is just regular alphanumeric data.

Just to make sure, please see if I converted your proc to VB correctly:

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)If m.Msg = &H87 Then
m.Result = New IntPtr(4) 'DLGC_WANTALLKEYS
Else
MyBase.WndProc(m)
End If
End Sub

Thanks


That's the right conversion - it caters for when the framework filters
out certain key presses.

Do you get the right sequence in KeyDown/KeyUp? If you're certain the
barcode data is alphanumeric (and normally has a CRLF at the end),
then I'm at a bit of a loss. Perhaps the driver for the reader is
opening a window somewhere that might affect focus? Spyxx might be
useful...

As a quick test. Put a textbox onto the form with a default button
("OK"). Set focus to the textbox and then scan the barcode. Does that
work?

Rgds,


Nov 20 '05 #6
I don't have a barcode reader, but magnetic stripe reader (although there
should be no difference in output). I have tried using the text box too, but
the result is the same - characters get lost.

You have kind of discouraged me because I am using Framework 1.0 and hoped
that upgrading to 1.1 may solve my problem.

Nevertheless, thanks for the input.
Niksa

"Fredrik Melin" <me*@n.o.spam.dacsa.net.remove.as.needed> wrote in message
news:uM**************@tk2msftngp13.phx.gbl...
Yes, Keypress and all keyinput events are buggy, in Framework 1.1 at least.
We have a larger app where the enter key stops working sooner or later (it
happens app wide, only restart will fix it..), instead the last button used get's clicked. (in my case i've teached the user to use cltr-enter instead
that seems to work all the time..)
But barcode readers work flawless in my application, both in modal and
modaless screens.
I let them scan to a text field though, with tab as last char, and then I
trap the input on normal validate event.

- Fredrik

"Niksa Baldun" <di***********@du.htnet.hr> wrote in message
news:u4*************@tk2msftngp13.phx.gbl...
Hi,

I have tried putting the textbox on the form, but the result is the same -
some characters don't make it to the textbox. BUT if I comment out the
KeyPress event handler, everything works fine. As long as the event handler
exists, even if there is no code in it, and even if KeyPreview is set to
False, the error persists. But it is also interesting that, in a modal

form
with only a command button on it, the error never appears.

Therefore I can only assume this is some kind of a bug in .NET framework, unfortunately the one I can't find the workaround for. I will try and see if
there are any patches available - perhaps the issue has been resolved.

Anyway, thanks for taking the interest in my problem.
Niksa
"_Andy_" <wi******@nospamthanks.gov> wrote in message
news:90********************************@4ax.com...
On Mon, 1 Dec 2003 09:03:09 +0100, "Niksa Baldun"
<di***********@du.htnet.hr> wrote:

>No, didn't help.
>
>I considered that focus my be shifted somehow, but it is not caused by input
>from the reader - it is just regular alphanumeric data.
>
>Just to make sure, please see if I converted your proc to VB

correctly: >
>Protected Overrides Sub WndProc(ByRef m As

System.Windows.Forms.Message) >If m.Msg = &H87 Then
> m.Result = New IntPtr(4) 'DLGC_WANTALLKEYS
>Else
> MyBase.WndProc(m)
>End If
>End Sub
>
>Thanks

That's the right conversion - it caters for when the framework filters
out certain key presses.

Do you get the right sequence in KeyDown/KeyUp? If you're certain the
barcode data is alphanumeric (and normally has a CRLF at the end),
then I'm at a bit of a loss. Perhaps the driver for the reader is
opening a window somewhere that might affect focus? Spyxx might be
useful...

As a quick test. Put a textbox onto the form with a default button
("OK"). Set focus to the textbox and then scan the barcode. Does that
work?

Rgds,



Nov 20 '05 #7

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

Similar topics

12
by: Trevor Fairchild | last post by:
I'm writing a program that is designed for quick navigation using specific buttons on the keyboard. In doing this, I have added a KeyPress event for every control on the form to intercept the key...
8
by: George Hester | last post by:
When the address bar is highligted? That is nothing on the page is selected. The address bar is selected. Capture keydown or keypress? Any ideas using javascript? Thanks. -- George Hester...
3
by: enki | last post by:
I am curios is there a way to do input with a single keypress in C++ or using a standard library? Basically if I want a menu to pop up and you choose 1-6 but you don't have to hit enter. Is...
4
by: owen | last post by:
I have an <input> box and i want to disable the apostrophe ( ' ) key, so when you press it, no character appears in the input box. All other keys should work ok. I can trap the keypress event...
4
by: phil_gg04 | last post by:
Dear Javascript Experts, I'm currently implementing Anyterm, a terminal emulator on a web page. It consists of an Apache module, some XmlHTTP and a bit of Javascript. The idea is to give you...
1
by: Darren Coleman | last post by:
I need help with 2 keyboard/input questions 1. How do i caputre all keypress events for my application/form? 2. How do I determine which keyboard sent the keypress? What i'm doing is using a...
0
by: LordHog | last post by:
Hello all, I am trying to implement an event handler for the KeyPress event for a cell within a DataGridView control. The obvous starting point from the DataGridView keypress event, but this...
10
by: Tim Frawley | last post by:
I am attempting to detect a Shift+Tab in the KeyPress event for back navigation on a control that doesn't support this method. Does anyone have any ideas how to compare e.KeyChar to a ShiftTab? ...
12
by: Todd Sparks | last post by:
I am using Visual Studio 2003 to develop a windows application in which I allow the users to just press Enter, while the focus is on a textbox, in order to perform a search. My problem is that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.