Simulating a keypress event. Please help. Anyone??????????????????????

[b][red]This message was edited by DrMarten at 2006-5-9 13:30:0[/red][/b][hr]
Hi,

Can anyone tell me how to pass values to the KeyEventsHandler or whatever to simulate a keyboard key being pressed please?

Imagine you wanted a process to automatically hit the ENTER or RETURN key for you ( as an example ).

This isn't for anything malicious by the way.
I'm not interested in doing a keylogging program.


Regards,

Dr M.



Comments

  • Use SendKeys.Send("{ENTER}") to simulate Enter key press.

    Use help to see all available keys sent by Sendkeys.Send


  • : Use SendKeys.Send("{ENTER}") to simulate Enter key press.
    :
    : Use help to see all available keys sent by Sendkeys.Send
    :
    :
    :
    you would also need to set the focus for a control that can respond to key events.

    [code]
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    TextBox1.Focus()
    SendKeys.Send("a")
    End Sub
    [/code]


    there is also the KeyPress, KeyDown events- but the 'e' KeyPressEventArgs object is Readonly and does not allow changing the KeyChar property

    [code]
    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress

    End Sub
    [/code]



  • I think this is what you are looking for:

    Dim e As New System.Windows.Forms.KeyEventArgs(Keys.Enter)
    ControlName_KeyDown(Me, e)


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories