Solved

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

Posted on 2004-10-29
355 Views
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.
0
Question by:BASESLydia
    5 Comments
     
    LVL 27

    Expert Comment

    by:planocz
    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
    0
     
    LVL 4

    Accepted Solution

    by:
       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
    0
     
    LVL 4

    Expert Comment

    by:eozz_2000
    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 :)
    0
     
    LVL 96

    Expert Comment

    by:Bob Learned
    SendKeys.Send("^{V}")

    Bob
    0
     
    LVL 1

    Author Comment

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    845 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

    Need Help in Real-Time?

    Connect with top rated Experts

    5 Experts available now in Live!

    Get 1:1 Help Now