Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by MattyZ · Oct 10, 2013 at 10:31 AM · windowsdesktopgesture

How to tie Unity app to Windows event

I'd like to build a Unity app which runs in the background on a Windows desktop, and does something - let's say, pops up a picture of a poodle - whenever somebody, say, waves their hand at the webcam.

Now let's assume I already have the gesture recognition software that knows when I wave at the webcam, my question is about the rest. How do I create a unity app which, once activated, sits in the background of the windows desktop until the gesture recognition event takes place, and then suddenly pops something up on the desktop.

Is this even possible in Unity?

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image CHPedersen · Oct 10, 2013 at 12:43 PM 0
Share

It depends. Are you okay with the Unity App still having a window, or do you need it to render in a way that integrates with the desktop, e.g. have parts of the Unity App be transparent against the windows desktop?

I have an idea how to implement the first, but I don't think it's possible to have Unity render "natively" onto the windows desktop outside the confines of its window.

avatar image MattyZ · Oct 10, 2013 at 12:54 PM 0
Share

I'm okay with the Unity App having a window. But the app would have to run when $$anonymous$$imized, constantly listening and waiting until the gesture is made, at which point an event in the app triggers an image to pop up.

avatar image CHPedersen · Oct 10, 2013 at 02:04 PM 0
Share

Okay, then I think I have a solution. Answer co$$anonymous$$g up.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by CHPedersen · Oct 10, 2013 at 02:20 PM

Okay, so basically, you need to programmatically control whether the window that houses the Unity application is visible on screen or not based on some event, and it should pop up automatically when this event occurs, i.e. the camera movement.

It's possible to control the visibility of a window by accessing the OS-level window id (the HWND) of the Unity App and then setting its visibility depending on this event. This means you're simply determining on the OS level whether to paint the window or not, including everything within it (Unity). The way this is done is with the Win32 API and some functions in User32.Dll which you access with the extern keyword. The functions you need are GetActiveWindow and ShowWindow, respectively:

HWND WINAPI GetActiveWindow(void);

BOOL WINAPI ShowWindow(_In_ HWND hWnd, _In_ int nCmdShow);

Don't be alarmed by the weird data types. Those are just Win32 API versions of integers. A HWND is a handle to a window which is implemented in C# as a pointer to an integer, i.e. an IntPtr. Make a class to house these functions called "WindowControlNative.cs" or something like that, and declare that you wish to use the functions like this:

 [DllImport("user32.dll")]
 static extern IntPtr GetActiveWindow();
 
 [DllImport("user32.dll")]
 static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);

You call GetActiveWIndow first to obtain the handle to Unity's OS window. You then pass the returned IntPtr to ShowWindow along with an integer that represents the command you wish to give it. See the list in the MSDN documentation I linked to for a thorough explanation. In short, though, hide and show would be 0 and 5, respectively, while maximize and minimize are 3 and 6. Experiment at your leisure.

The next task is to hook it up to this camera-hand-wave code you've got going on. I'm assuming you have a framework that triggers some kind of callback or event from this camera? In a handler for that event, you'd just call ShowWindow with your window handle and give it the integer command for Show or Maximize, depending on what behavior you want. I'm hoping this all makes sense? Let me know if you have more questions.

Edit:

I forgot mentioning that if your webcam code runs in sync with the Unity API and depends on its continuous updating to run, then you need to set Application.runInBackGround to true to make sure Unity is still invisibly rendering frames while the window is hidden.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Help - Kinect for windows v2, Gesture recoginition 3 Answers

Accelerometer access in Windows Desktop. 0 Answers

Run Unity app as Windows Wallpaper/Desktop Background 1 Answer

Get desktop icons position on Windows 0 Answers

multitouch on desktop possible 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges