- Home /
Trap the Windows Key
In testing our game, we find users are accidentally hitting the Windows Key more often than we thought, disrupting the game play. Even when moving the core gameplay keys away from the windows key, it still happens (younger audience game).
Has anyone found a way to trap the Windows Key and shunt its behavior? I've been told that being a system key it's not trappable in Unity 3.0 via script, but wanted to confirm or deny.
Thanks for any input.
Answer by qJake · Jun 28, 2010 at 09:02 PM
Well, there are two events that correspond to the Windows keys on a keyboard. Have you tried using them, or perhaps setting them up in the Input Manager so that they bind to the game?
If that doesn't work, short of writing a C++ plugin, I think you're out of luck. Even in regular programming, it's somewhat difficult to trap the Windows key, and in fact most retail video games don't even bother with it.
The event way won't help, but +1 as the c++ way will: http://stackoverflow.com/questions/1161053/capturing-keystrokes-without-focus
That question is for $$anonymous$$edia buttons, not the Windows key, which behaves differently. I believe you have to capture the event and tell the OS to cancel the event, while perfor$$anonymous$$g your own action (or doing nothing). It's harder than just capturing keys, iirc.
Thanks for the insight, everyone. I will investigate the C++ way.
Sorry to delay. Thanks for the insight on how to approach this.
Your answer
![](https://koobas.hobune.stream/wayback/20220613063337im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
on windows player or standalone, numerical keys is a mess 1 Answer
How to disable CTRL key interference on Windows? 0 Answers
Prime31 azure plugin can't build 0 Answers
Unity 5 editor in Windows 64 vs 32 bit 2 Answers
Unity error 2 Answers