Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
Hello, how can i simulate a keyboard press. I mean i have lets say a string "Hello". i want to iterate through the characters of the string and simulate a keypress of the read character. So if a notepad is opened while execution and the its active, then hello will be printed on the notepad
  • *Experts*
Posted

This api will do what you want:

http://www.mentalis.org/apilist/keyb_event.shtml

Example(from the site, but modified to work in .net:

   Const VK_H = 72
   Const VK_E = 69
   Const VK_L = 76
   Const VK_O = 79
   Const KEYEVENTF_EXTENDEDKEY = &H1
   Const KEYEVENTF_KEYUP = &H2
   Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Integer, ByVal dwExtraInfo As Integer)

   Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Me.Show()
       Do While Me.Created
           keybd_event(VK_H, 0, 0, 0)  ' press H
           keybd_event(VK_H, 0, KEYEVENTF_KEYUP, 0)  ' release H
           keybd_event(VK_E, 0, 0, 0) ' press E
           keybd_event(VK_E, 0, KEYEVENTF_KEYUP, 0) ' release E
           keybd_event(VK_L, 0, 0, 0) ' press L
           keybd_event(VK_L, 0, KEYEVENTF_KEYUP, 0) ' release L
           keybd_event(VK_L, 0, 0, 0) ' press L
           keybd_event(VK_L, 0, KEYEVENTF_KEYUP, 0) ' release L
           keybd_event(VK_O, 0, 0, 0) ' press O
           keybd_event(VK_O, 0, KEYEVENTF_KEYUP, 0) ' release O
           Application.DoEvents()
       Loop
   End Sub

  • Leaders
Posted

if you just want the ability to open something like notepad and write to it when it opens you can do this :

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       Shell("notepad.exe", AppWinStyle.NormalFocus)
       SendKeys.Send("hello") '/// wont work with Process.Start , but will with Shell
   End Sub

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...