- Home /
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!
Answer by xamomax · Jul 20, 2016 at 12:03 PM
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:
https://docs.unity3d.com/Manual/CommandLineArguments.html
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.
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
No, Unity is a completely seperate application that doesn't even share any memory. All he did is parenting Unity's device context to a window of a different application. Unity is still a seperate application. Of course you could communicate between the two applications through sockets or similar things.
Your answer
![](https://koobas.hobune.stream/wayback/20220612084925im_/https://answers.unity.com/themes/thub/images/avi.jpg)