Link to home
Start Free TrialLog in
Avatar of BASESLydia
BASESLydia

asked on

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

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.
Avatar of Howard Cantrell
Howard Cantrell
Flag of United States of America image

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
ASKER CERTIFIED SOLUTION
Avatar of eozz_2000
eozz_2000

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of eozz_2000
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 :)
SendKeys.Send("^{V}")

Bob
Avatar of BASESLydia

ASKER

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