Solved

? Detecting Keyboard Errors ?

Posted on 2004-09-07
3
252 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 109 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Gridview selected row 9 49
start a process from a service 3 30
Footer for each row on Gridview 2 30
Create a datatable in vb.net dynamically 1 22
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…

792 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