[Webinar] Streamline your web hosting managementRegister Today


How can you create a Windows.Forms.Keys that represents Ctrl + V being pressed?

Posted on 2004-10-29
Medium Priority
Last Modified: 2008-02-01
It says in the VS.NET documentation that you can use the bitwiseor to combine enumerated key values to create a key that represents the control key modifier and the V key. I have tried all sorts of ways to do this and I can't get it to work!

Dim kyCtrlV As Windows.Forms.Keys
kyCtrlV = Keys.V  | Keys.Control - doesn't work

basically i am trying to call a ss_Data_KeyUp method that takes a System.Windows.Forms.KeyEventArgs parameter and I want to set the System.Windows.Forms.KeyEventArgs key to by Ctrl V so I can imitate the user pasting data.
Question by:BASESLydia
LVL 27

Expert Comment

ID: 12446320
Add this to your form...

    Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
        Const WM_KEYDOWN As Integer = &H100
        Const WM_SYSKEYDOWN As Integer = &H104
        Dim e As System.EventArgs

        If ((msg.Msg = WM_KEYDOWN) Or (msg.Msg = WM_SYSKEYDOWN)) Then
            Select Case (keyData)
                Case Keys.ControlKey.V
                    'Do something
            End Select
        End If
        Return MyBase.ProcessCmdKey(msg, keyData)
    End Function

Accepted Solution

eozz_2000 earned 2000 total points
ID: 12446336
   Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
        If e.Control Then
            If e.KeyCode = Keys.V Then
                MsgBox("Ctl + v")
            End If
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim r As KeyEventArgs
        r = New KeyEventArgs(r.Modifiers.Control Or Keys.V)
        Me.TextBox1_KeyDown(Me.TextBox1, r)
    End Sub

Expert Comment

ID: 12446356
In that way you create a KeyEventArgs that has the control set to True and the keyCode of V

I hope this could help you :)
LVL 96

Expert Comment

by:Bob Learned
ID: 12446440


Author Comment

ID: 12447053
r = New KeyEventArgs(r.Modifiers.Control Or Keys.V)
That did it! Thank you so much.

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
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…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses

607 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