Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


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
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
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

604 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