473,770 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 indistinguishab le 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 4482
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 indistinguishab le 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_WANTALLKEY S
}
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_WANTALLKE YS
Else
MyBase.WndProc( m)
End If
End Sub

Thanks

"_Andy_" <wi******@nospa mthanks.gov> wrote in message
news:pa******** *************** *********@4ax.c om...
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 indistinguishab le 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_WANTALLKEY S
}
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_WANTALLKE YS
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******@nospa mthanks.gov> wrote in message
news:90******** *************** *********@4ax.c om...
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_WANTALLKE YS
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******** *****@tk2msftng p13.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******@nospa mthanks.gov> wrote in message
news:90******** *************** *********@4ax.c om...
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_WANTALLKE YS
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.d acsa.net.remove .as.needed> wrote in message
news:uM******** ******@tk2msftn gp13.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******** *****@tk2msftng p13.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******@nospa mthanks.gov> wrote in message
news:90******** *************** *********@4ax.c om...
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_WANTALLKE YS
>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
24191
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 pressed and pass it to a standard subroutine that identifies what action should be taken. Unfortunately, I have a web-browser contol on the form and the webbrowser does not include a KeyPress event. I need some way to intercept keypress and...
8
2864
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
6957
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 this possible?
4
10548
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 using "onkeypress=myKeypressHandler()" but, beyond that, I'm stuck. I forget how to detect what key was pressed or how to "null it out". I'm using IE6 and users will be IE5.0 upward ONLY (trust me on this, suffice to say it's not a website but...
4
8988
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 shell access to your server from (almost) anywhere; other solutions to the problem tend to require access to ports other than 80 and Java. The very primitive first attempt is at http://chezphil.org/anyterm/. A more functional version will be...
1
6195
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 USB Barcode scanner, windows sees the scanner as a keyboard. When the scanner reads a barcode it decodes the barcode and sends in the decoded values in as keypresses from a keyboard. I want to be able to tell the diffrence between a keypress from a...
0
3398
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 doesn't work for the cell. I found this posting while searching, but this doesn't work with the .NET 2.0 beta framework. http://www.csharphelp.com/board2/read.html?f=1&i=35363&t=30532
10
27893
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? Tim
12
6544
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 sometimes Keypress event stops being raised. I have found that I can reproduce this behavior by performing a search, opening up another form, then trying to perform another search. The second search will NEVER work. How can I fix this problem? ...
0
9618
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10038
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9906
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8933
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7456
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6710
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2849
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.