Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 flyingchicken · Sep 07, 2021 at 12:54 PM · inputtouch controlsinteractionmouse control

Check for any input

How would I go about checking for any input whatsoever? Input.anyKey returns true if a key or mouse button is pressed but not if the mouse wheel is scrolled. I'd like to know if there is a variable/function call that can tell me when the user has performed any form of interaction with my game. Whether it's a key press, mouse click, mouse movement, touchscreen press, finger movement, etc.

Comment
Add comment · Show 6
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 flyingchicken · Sep 07, 2021 at 12:56 PM 0
Share

For context, what I'm essentially implementing is a "sleep mode" that temporarily disables rendering to when the user is idle but immediately wakes up when any interaction is detected. This is to save battery on mobile devices.

avatar image logicandchaos · Sep 07, 2021 at 01:01 PM 0
Share

you could use || to include all the different inputs.

avatar image flyingchicken logicandchaos · Sep 07, 2021 at 01:23 PM 0
Share

I understand that but my issue is that there could be an input type that I miss. I'm developing for many different platforms so might forget/overlook something. The reason I asked this question is that I had code similar to what you suggested and, during testing, I tried scrolling the mouse wheel and it was not detected. To detect a mouse wheel scroll will require me to make a new variable to check if the axis value is different on the current frame to the last frame. This will make my code bloated especially if there are other inputs that are missed. I'd much prefer to simply have: if (Input.AnyInput) { WakeUp(); }

avatar image Bonfire-Boy · Sep 07, 2021 at 02:08 PM 0
Share

I'd be a bit surprised if there were such a thing.


Obviously, don't know your exact needs, but on the face of it your use-case seems strange to me.


1. Having to actively choose to wake a device/app up after it goes to sleep is pretty standard. So is there really a big advantage to having any interaction wake it up (as opposed to a "Resume" button for instance)?

2. Why go to the trouble, when people can manage their own battery life? Chances are their phone or whatever will have gone into sleep mode anyway.


avatar image flyingchicken Bonfire-Boy · Sep 07, 2021 at 03:19 PM 0
Share

Hi, I don't think I was super clear. "Sleep Mode" keeps the screen on and the app running, it just uses the OnDemandRendering class to reduce framerate to 1fps. It's essentially for when the screen becomes static so anything more than 1fps is wasteful. My app allows users to rotate and zoom in on a 3d model but when they aren't directly doing that it's essentially just a static image.

avatar image Bonfire-Boy flyingchicken · Sep 07, 2021 at 04:02 PM 1
Share

Ah ok, fair enough. And your sleep mode kicks in earlier than people's own battery-saving stuff would...?


But to flesh out my first sentence a bit more... input devices are (architecturally if not physically) peripherals. So I'm not sure that it'd be feasible or desirable to have a function call of the sort you're suggesting in the engine. To maintain a core function that truly reported on all input devices, anyone who added a plugin for a new input device would have to somehow be compelled to register with it.


And what inputs are inputs? I'm working mostly in VR - is headset movement an input or not. Answer - for some apps, maybe. What about a phone's gyro/accelerometer inputs? Again - for some apps. And if they are you'd probably want to only consider such an input a "wake-up-worthy" input if it exceeded some threshold anyway.


So for me it makes sense to leave this stuff to the developers of specific apps to decide which inputs they care about.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by RKadeZone · Sep 07, 2021 at 03:32 PM

Not sure this is possible, reference this https://forum.unity.com/threads/input-manager-detect-any-key.13607/#post-94769


However, you should be able to get what you described in a single if check by or'ing the calls together.

 if (Input.anyKeyDown || Input.GetAxis("Mouse ScrollWheel" || ..) 
 {
     // code
 }


Note: Unity doesn't provide a way to detect finger swipes afaik, but you can accomplish that in three lines of code shown here: https://answers.unity.com/questions/1572835/moving-object-with-finger-move.html

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

163 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 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image

Related Questions

Unity3d touch input on regular pc`s with an touch pc-monitor,,Track Touch events on an PC with an Touch-Screen 2 Answers

touchcount does not reset between game runs 0 Answers

Touch input 1 Answer

how to change default third player controls in unity, to work with touch? 1 Answer

EventSystem.current.IsPointerOverGameObject(t.fingerId) - Not working on Android builds - Unity 2 Answers


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