How to send keyboard and mouse input to an embedded Unity player launched with -parentHWND?

I am using the Unity Stand Alone Player command line option “-parentHWND” to embed Unity into a Windows application (created in Delphi XE10, though I don’t think that matters). This is working awesome, except for one problem: I cannot get mouse or keyboard input into the Unity part.

When I run inside of Unity, or as a standalone exe, the keyboard and mouse inputs work great. When I embed, the host application receives all the inputs instead, locking out the Unity player.

Presumably I need some way to send a message to “pass on” these inputs to the Unity part. I am fairly new to Unity, so how would I do that? What kind of external messages can I send that Unity will accept? Or, perhaps I need to use some special mode to “get global inputs” or something like that, if there is such a thing? What is the right way to solve this?

Thanks!

Hi @BugFighter, please let me know if you found this answer helpful? If so, could you please be so kind as to click the "Accept" button above to accept the answer? Thank you!

2 Answers

2

To those of you also wondering the answer to this, I have come across the solution.

The trick is that the embedded Unity application must be “Activated”. How to do this can be found in a sample project .zip file, which you can get in the -parentHWND section of this page:

The long story short of it, is that you have to find a handle to the Unity Window, and then once you have that handle, you can send a Windows message to “activate” it.

A key point here, is that it actually has a Windows Handle, which opens it up to Windows Messaging in general, I suppose.

If you happen to be a Delphi user, and would like some Delphi source code for this, send me a message, and Hopefully I’ll get to it and post it back here for you, once I’ve cleaned it up a bit.

I hope this helps someone.

Thank you! This was of great help!

Hi, I'm interested in a Delphi solution if you still have one available. Can you add objects to the unity scene via Delphi? Cheers Greg

Hi,

I’m interested in a Delphi solution if you still have one available. Can you add objects to the unity scene via Delphi?

Cheers

Greg