JumpyNET Posted April 27, 2005 Posted April 27, 2005 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.