Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I need to launch another app and command it to start a certain function. The function can be started by pressing F4. I have accomplished that with the code below. But I'd like to replace the EmulateKeyPress() with something that works better.

 


Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

#Region "Emulate KeyPress"
   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 Long, ByVal dwExtraInfo As Long)
   Private Function EmulateKeyPress(ByVal KeyCode As System.Windows.Forms.Keys)
       keybd_event(KeyCode, 0, 0, 0)  ' Press
       keybd_event(KeyCode, 0, KEYEVENTF_KEYUP, 0)  ' Release
   End Function
#End Region

Private Sub Button_ProcessFiles_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_ProcessFiles.Click
       Process.Start("TheOtherApp.exe")
       Sleep(500)
       EmulateKeyPress(Keys.F4)
End Sub

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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...