Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

? Detecting Keyboard Errors ?

Posted on 2004-09-07
3
Medium Priority
?
262 Views
Last Modified: 2010-04-23
i am useing VB.NET, and working within a windows form.

in my form i am useing SendKeys.SendWait(var)
sometimes the focus of my target application changes, and when i send the key stroke i get a keyboard error, ie. a "beep" sound from the system.

is there anyway to detect this error? this would be done so i can resend the key that resulted in an error.

thanks.
0
Comment
Question by:frosty5656
  • 2
3 Comments
 
LVL 27

Accepted Solution

by:
planocz earned 327 total points
ID: 12005585
Here is a function that you can use to catch the key strokes before it gets to the other Keypress events...

SAMPLE:

   Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
        Const WM_KEYDOWN As Integer = &H100
        Const WM_SYSKEYDOWN As Integer = &H104

        If ((msg.Msg = WM_KEYDOWN) Or (msg.Msg = WM_SYSKEYDOWN)) Then
            Select Case (keyData)
                Case Keys.A
                    TextBox1.Text = "Key A"
                Case Keys.Left
                   TextBox1.Text = "Key Left"
                Case Keys.Down
                       TextBox1.Text = "Key Down"
                Case Keys.Up
                    Me.Parent.Text = "Up Arrow Captured"
                Case Keys.Tab
                    Me.Parent.Text = "Tab Key Captured"
                Case (Keys.Control Or Keys.M)
                    Me.Parent.Text = "<CTRL> + M Captured"
                Case (Keys.Alt Or Keys.Z)
                    Me.Parent.Text = "<ALT> + Z Captured"
            End Select
        End If

        Return MyBase.ProcessCmdKey(msg, keyData)
    End Function
0
 

Author Comment

by:frosty5656
ID: 12013213
thanks for the reply.

i don't understand how capturing what key is being pressed helps my problem? will this function return a value when a keyboard error occurs? sorry i'm fairly new to vb.net, could you explain your solution a bit more?

thanks.
0
 
LVL 27

Expert Comment

by:planocz
ID: 12015321
This will pickup any key that you are using. If you have to press a special key this will pick it up.
There is no need to look just for errors.
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Integration Management Part 2
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question