You can send "Alt Tab" to get the focus back:
Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Const VK_TAB = &H9
Const VK_MENU = &H12 'ALT
Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long
**************************
Sub sendAltTab
keybd_event VK_MENU, MapVirtualKey(VK_MENU, 0), 0, 0 ' 0=press alt
keybd_event VK_TAB, MapVirtualKey(VK_TAB, 0), 0, 0
keybd_event VK_TAB, MapVirtualKey(VK_TAB, 0), 2, 0
DoEvents
keybd_event VK_MENU, MapVirtualKey(VK_MENU, 0), 2, 0 ' 2=release alt
End Sub
**************************
Main Topics
Browse All Topics





by: Latzi_MarianPosted on 2008-05-13 at 20:32:20ID: 21561054
Hi,
I would like to rectify.Getting the focus is not an issue.The problem is when the program is started and has the focus how to simulate or tell the system that key F2 is pressed??