Hey people! I want to "sendkeys" to another application. How to focus on that application? Basically I have:

Hey people! I want to "sendkeys" to another application. How to focus on that application? Basically I have:

procedure keybd_event(bVk: Byte; bScan: Byte; dwFlags: DWORD; dwExtraInfo: UIntPtr); stdcall;

Maybe dwExtraInfo is the solution, but I dont see any help about.

Thank you for any tip.

Comments

  1. Use UI Automation. Faking input like this using SendInput (don't use keybd_event as per docs) is fraught with problems. See questions ad nauseam on SO.

    ReplyDelete
  2. Agree with David, but if UI Automation is not accessible, then use SetForegroundWindow.

    ReplyDelete
  3. Just came across this github project that wraps the UI automation API

    https://github.com/jhc-systems/DelphiUIAutomation

    ReplyDelete
  4. Wow! Very nice tips!! Thank you guys, I will gonna check and let you know.

    ReplyDelete
  5. Herbert Sauro question here is by running the examples it will allow Automation between Delphi applications, but if I need to sendkey/automate another software, such Notepad.exe I did not found how to, and that's my case.

    ReplyDelete
  6. UI Automation is not limited to Delphi. What makes you think that? I suspect you have not fully researched what this thing is.

    ReplyDelete
  7. David Heffernan It is true! Following the example I ran and by see that there are specific UI components, edit, label, grid, etc made me think it is limited. I will study it more fully. Thank you David.

    ReplyDelete
  8. Some components aren't supported in jhc-systems but you might be able to add those or contact the author. What I would do is search stackoverflow and see how others have used UI Automation in say C#. The Delphi wrapper project should also help a lot however.

    ReplyDelete
  9. Maybe you could try PostMessage with WM_KEYDOWN and WM_KEYUP: e.g PostMessage(FindWindow('Target Program Caption','Classname'),WM_KEYUP, VK_RETURN,0);

    ReplyDelete
  10. And when that fails ask that question on SO that is asked 10 times every day.....

    ReplyDelete

Post a Comment