- Home /
Limitation of using OnGUI for Touchpad "ScrollWheel"?
Thanks to a few suggestions I've found here I'm using OnGUI() to use the ScrollWheel Event to add a Camera Zoom effect. It works great, as long as I'm not doing anything else.
But if I'm using the keyboard to control my character ("WASD"), then the OnGUI Event is for the keyboard, and doesn't pick up the MouseWheel event from the Touchpad.
Any suggestions on a workaround? I've looked at the Event.PopEvent but there's almost no documentation on how it works or what to do with it, so I'm not sure if I'm just missing a workaround.
Answer by jcgray83 · Oct 01, 2017 at 04:55 AM
EDIT Ok, the Mouse/Keyboard inputs seem to be a limitation on my laptop. I decided to test outside of Unity and pressing any keys on my keyboard essentially shuts off my Touchpad. There's probably a setting somewhere in Windows or my Touchpad software that's limiting me.
/EDIT
This code runs fine if I do not use any keys on my keyboard. But holding W to have my character run forward makes this stop.
If I'm not touching the keyboard, and "Scroll" with the Touchpad, and while still scrolling I press a keyboard key everything works as it should. The moment I stop touching the Touchpad means I can't scroll until I stop using the keyboard.
And Input.GetAxis("Mouse ScrollWheel") does not work with touchpads, hence the use of OnGUI().
public void OnGUI()
{
if (Event.current.isScrollWheel)
// do stuff with Event.current.delta
cameraController.CameraDolly(Event.current.delta.y / 100);
}
A lot modern laptops do this artifically to prevent accidental mouse actions with your palms rubbing across the touchpad while typing something.
See this SU question for potential solutions. Though it might depend on your exact hardware and software. You actually find tons of software tools which implement such a palmcheck artifically. $$anonymous$$aybe your OS installation comes with such a tool pre-installed.
I finally fixed the issue, partly from your link, and partly from a google search.
One suggestion that was given was in Windows 10, Settings -> Devices -> Touchpad -> Click Delay While Typing. In the newer versions of Win10 that setting has been replaced by Sensitivity. Changing my Sensitivity to "$$anonymous$$ost Sensitive", the highest setting, now allows me to use my mouse and click while typing.
Answer by Bunny83 · Oct 01, 2017 at 02:13 AM
I don't quite get your second paragraph. OnGUI does process many different events.which includes key, mouse and scrollwheel events. OnGUI is called for each event seperately.
Event.PopEvent shouldn't be used manually as it will permanentally remove an event from the event queue which prevents any other script or system to process this event. It's used by the new UI system internally to get the UI events.
What does your actual code look like?
As an alternative you should be able to use the virtual input axis named "Mouse ScrollWheel" in conjunction with Input.GetAxis. Even the axis is usually defined by default it's possible that you or something else in your project has remove it from the Input manager. So if it doesn't work, check the input manager (Edit --> Project Settings --> Input).
Your answer
Follow this Question
Related Questions
How to get ScrollWheel values using a laptop touchpad? 1 Answer
Touch pad "wheel" problem 0 Answers
Trackpad and Mouse can't fix scroll speed! 1 Answer
OnGUI() not showing anything 2 Answers
Iterating LList in OnGUI(), slow? 0 Answers