Solved

SendKeys issue

Posted on 2007-03-21
3
266 Views
Last Modified: 2012-08-14
I'm trying to send keystrokes to activate context-menu events from one control to another.

I have a textbox, txtSearch which has the following procedure:

    Private Sub txtSearch_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtSearch.KeyUp

        If e.Control = True Then

            trvInventory.InventoryTree_KeyUp(sender, e)

        End If ' e.Control = True

    End Sub

And trvInventory has the following procedure:

    Public Sub InventoryTree_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp

        If Not (sender Is Me) Then

            Dim strKeys As String = ""

            If e.Control = True Then
                strKeys = "^"
            End If ' e.Control = True

            strKeys &= Chr(e.KeyCode)

            Me.Focus()

            SendKeys.SendWait(strKeys)

            CType(sender, Control).Focus()

        End If ' Not (sender Is Me)

    End Sub ' InventoryTree_KeyUp

However, the code does not activate the context-menu shortcut.  What am I doing wrong?
0
Comment
Question by:jake072
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 18767339
Try sendkeys +{F10}
0
 
LVL 27

Accepted Solution

by:
planocz earned 500 total points
ID: 18768937
Add this code to your form and test it
With this function you can change it to find the key that you want.

    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 To Keys.Z                                '<--- Catch the Keys you want
                    MessageBox.Show("You pressed " & ChrW(keyData))  '<--- Then do something
                Case Keys.Right
                    Me.Text = "Right Arrow Captured"
                Case Keys.Left
                    Me.Text = "Left Arrow Captured"
                Case Keys.Down
                    Me.Text = "Down Arrow Captured"
                Case Keys.Up
                    Me.Text = "Up Arrow Captured"
                Case Keys.Tab
                    Me.Text = "Tab Key Captured"
                Case (Keys.Control Or Keys.N)
                    Me.Text = "<CTRL> + N Captured"
                Case (Keys.Alt Or Keys.Z)
                    Me.Text = "<ALT> + Z Captured"
                Case Keys.NumPad0
                    Me.Text = "Num Pad '0' Captured"
                Case Keys.Delete
                    MessageBox.Show("Delete Captured")
                Case Keys.NumLock
            End Select
        End If

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

Author Comment

by:jake072
ID: 18771160
planocz,

By using your code, and changing the sub's to friend in my control, it works perfectly...  Should've thought of that :)

My code:

    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.Control Or Keys.I)
                    trvInventory.ctxCreateItem_Click(Nothing, Nothing)

                Case (Keys.Control Or Keys.M)
                    trvInventory.trvInventory_DoubleClick(Nothing, Nothing)

                Case (Keys.Control Or Keys.D)
                    trvInventory.ctxDelete_Click(Nothing, Nothing)

                Case (Keys.Control Or Keys.Q)
                    trvInventory.ctxResetQty_Click(Nothing, Nothing)

                Case (Keys.Control Or Keys.C)
                    trvInventory.ctxCreateGroup_Click(Nothing, Nothing)

                Case (Keys.Control Or Keys.O)
                    trvInventory.ctxModifyGroup_Click(Nothing, Nothing)

                Case (Keys.Control Or Keys.G)
                    trvInventory.ctxDeleteGroup_Click(Nothing, Nothing)

                Case (Keys.Control Or Keys.N)
                    trvInventory.ctxManageDelete_Click(Nothing, Nothing)

                Case (Keys.Control Or Keys.R)
                    trvInventory.ctxResetPricing_Click(Nothing, Nothing)

            End Select ' (keyData)

        End If ' ((msg.Msg = WM_KEYDOWN) Or (msg.Msg = WM_SYSKEYDOWN))

        Return MyBase.ProcessCmdKey(msg, keyData)

    End Function ' ProcessCmdKey

Thanks!

Jake
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Filtering a datagrid view 8 43
Check only one toolstripmenu item 12 60
Call a VB.net function in Javascript 6 51
VB.NET Parsing UDP Bytes 15 36
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

732 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