Java JNA focus a specific Window

后端 未结 4 705
Happy的楠姐
Happy的楠姐 2021-01-07 03:59

I am trying to give my application the power to focus another Window (Notepad in this case)

My Class is looking like this

 public static class Win32W         


        
4条回答
  •  悲哀的现实
    2021-01-07 04:32

    Answer by Avinash Jha is good. Just add following two lines after user32.SetForegroundWindow(hWnd);, you will not need to add robot keys VK_ENTER to activate window, as clicking enter will cause clicking default key of window (e.g. button OK, Run)

    ...
    user32.SetForegroundWindow(hWnd);
    
    user32.SetFocus( winOne.winHandle);
    Thread.sleep(500);
    user32.ShowWindow(winOne.winHandle, WinUser.SW_SHOWNOACTIVATE);
    
    return false;
    ...
    

提交回复
热议问题