Game Development Community

Disabling the Windows Key (TGE 1.5.2)

by Pisal Setthawong · 02/16/2009 (10:52 am) · 18 comments

The Window Key can easily cause problems if the PC game is running in Full-Screen mode as it will switch into the window mode unintentionally. To deal with that, this resource will explain a quick hack on how to disable the Windows Key.

The hack was done in my modified TGE 1.5.2 for the PC and is not guaranteed to work TGEA or TGB, though theoretically it should.

To disable the Windows Key, we will have to do a low level catch for the input keys, and reroute the Windows Key to do nothing.

The first step in the process is that we have to update the Windows constant of TGE to be a modern enough version to support some of the new commands.

In PlatformWin32/PlatformWind32.h starting line 16-18
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0400
#endif

Change it into:
#ifndef _WIN32_WINNT
//Pisal Add to Remove Windows Keys from the Game
#define _WIN32_WINNT 0x0500
//Pisal END
#endif

This will make sure that the compiler can grab the new macros you need to disable the keys.

The second step is to write a hook that will steal the input and silently discard the windows key.

Add the following function after the function declaration part (or anywhere you like before the function WinMain) in the PlatformWin32/winWindow.cc
//Pisal Add to Remove Windows Keys from the Game
LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{ 
	PKBDLLHOOKSTRUCT p = (PKBDLLHOOKSTRUCT)lParam;

	//disable left Window Button
	if (nCode==HC_ACTION && p->vkCode==VK_LWIN && (wParam==WM_KEYDOWN || wParam==WM_SYSKEYDOWN))
	{	 
		return 1;
	}
	
	//disable Right Window Button
	if (nCode==HC_ACTION && p->vkCode==VK_RWIN && (wParam==WM_KEYDOWN || wParam==WM_SYSKEYDOWN))
	{	 
		return 1;
	}

	return CallNextHookEx(0,nCode,wParam,lParam);
}
//Pisal END

After finishing writing the hook, we need to inform TGE that we would be loading the hook to the game. In the same file PlatformWin32/winWindow.cc, find the following code:
S32 PASCAL WinMain( HINSTANCE hInstance, HINSTANCE, LPSTR lpszCmdLine, S32)
{

and add
//Pisal Add to Remove Windows Keys from the Game
	HHOOK hook = SetWindowsHookEx(WH_KEYBOARD_LL, LowLevelKeyboardProc, hInstance, 0);	
	//Pisal END

This would now inform TGE that it will have to hook the input to the custom hook we wrote earlier, and if we noticed careful, the custom hook we wrote actually silently discards all of the left and right Window Key presses :)

For fun you can silently discard any other keys that you want. One warning though is that you shouldn't go overboard and try to discard all keys that is not necessary. This might cause usability issues with your program later!

On a related issue, if you are having trouble with Window Switching in Full-Screen mode, I want to grab your attention to ALT+TAB Fix at the the following resource by Alex Stone: www.garagegames.com/community/forums/viewthread/74471. I believe that resource could be used in conjuction with this one to would help you a lot regarding full-screen woes that you might be having.

About the author

An Educator moonlighting as the Technical Lead at the indie game development studio called Flying Pig Game Studio


#1
02/16/2009 (1:42 pm)
Very good!
#2
02/17/2009 (2:42 am)
I would suggest not doing this, at least not as a default behavior. Messing with the expected operation of Windows tends to annoy people. Better to let the user deal with the consequences of hitting the wrong key by accident and make sure the game can handle it gracefully. If you want to make it an option that the user can enable, that would be fine, but I know a few anal people that would refuse to play the game if/when they discover that it does that by default.

Plus some people use the Windows key to help them escape full screen mode if the game UI stops responding correctly for any reason, which seems to happen with every FS game at some time or another.
#3
02/17/2009 (8:06 am)
I like it.

Who is going to be playing a game in fullscreen and have the urge to stop playing by pressing their windows key to bring up the windows start menu? They should have better ways to escape full screen such as Alt+Enter, Alt+Tab, heck even CTRL+ALT+DEL.

Nobody I know ever even uses the windows key, it's pretty useless. Unless maybe you have no mouse or can't find the "start" button lol.

I say screw the windows key!
#4
02/17/2009 (8:56 am)
Agree with Joe! Alt+Tab 'til I die...
#5
02/17/2009 (1:29 pm)
Im at the other side actually, I feel pissed off when playing a game and hit the windows key, so I prefer the game to block it.

After all, is just another key, is part of the hardware of the computer and should not be considered "owned" by a functionality.

You press 'A' and it does not prints an A on the screen, the player moves fordward instead. I dont see the problem in remaping a function for a better game functionality, even if it means to disable that key.
#6
02/17/2009 (1:41 pm)
Yeah! We should do away with all system keys while inside a game. If it craps out... well, we still have the power button -- it always works for backing you out of a "hung up" program ;)

@Pisal: Nice job showing people "who want to know how" how to do this.
#7
02/17/2009 (2:23 pm)
@Michael: dont know if you are beeing sarcastic or not, but I dont think remaping a key is the same as get ride of all the "system keys". As said before, there are already other key combinations of typical use in case of hung ups.

I think the O.S. is already consuming FAR too much resources on the computer, but to start thinking that it owns parts of my keyboard is a bit too much ;)
#8
02/17/2009 (2:48 pm)
Quote:
Who is going to be playing a game in fullscreen and have the urge to stop playing by pressing their windows key to bring up the windows start menu?

It doesn't really matter if they have the urge to do it or not, some people simply won't trust your program if it does stuff like that. Trust me on this one, I've already been down that road. They will call it a hack and start questioning what else the game is doing that it shouldn't be doing. Slightly irrational perhaps, but it is what it is. Not really something an Indie can afford.

Quote:
They should have better ways to escape full screen such as Alt+Enter, Alt+Tab, heck even CTRL+ALT+DEL.

Should is not the same thing as does. You'd be surprised how many people don't know how to Alt-Anything.
#9
02/17/2009 (2:59 pm)
Quote:It doesn't really matter if they have the urge to do it or not, some people simply won't trust your program if it does stuff like that.
Gerald, I admit there is people for everything. However! Im a pc gamer, and been a gamer all my life. I practically grew up alongside PC games. My friends too. My family too. My sisterms play casual games to Tomb Raider. Ive been in gaming forums a lot.

Ive never, NEVER, in my life, read or heard something like your quote.

Now, I believe you saw that, is possible, its just not enough to consider something seriously. Beeing there, I can tell that on the other side I know a about a lot of times when SO and special keys got in the way of a good match.

And finally... if the user dont know about C-A-D, or Alt-Anything, then may be a problem beyond scope: the user doesnt know how to use a computer!
#10
02/17/2009 (4:10 pm)
Quote:
Ive never, NEVER, in my life, read or heard something like your quote.

How many games have you been involved with the communities that have disabled system keys?

It's not something that many game makers do (for a reason), so you're not likely to come across something like that directly. I have had to deal with it directly, mainly for third party addons to games. Even when it was added to an addon for a game that crashed completely when the Windows key was pressed, there were complaints.

But don't tell me you've been an avid PC gamer involved with gaming forums and haven't seen the phenomenon where with some people, every time their Zone Alarm or Norton beeps, they blame it on the game or the makers of third party addons. The same people that do that are the ones that will call you a hack if you disable their system keys.

You are, of course, free to do what you like. I would just recommend against doing it as a default behavior. Make it an option that the user can turn on if they want.


Quote:
And finally... if the user dont know about C-A-D, or Alt-Anything, then may be a problem beyond scope: the user doesnt know how to use a computer!

In user experience testing for Microsoft Office 2007, the average time it took people to figure out how to save a file was something like 20 minutes, because there was no menu bar and they didn't know Alt-F or Ctrl-S, or even the significance of the little disk icon. That's why in the final release, the first time you run it, it will open the Application menu so it's in your face.

It's a common trap to fall into to assume that because you know something it must be common knowledge. Users can be pretty clueless, but they're the ones that pay your bills.
#11
02/17/2009 (4:39 pm)
Quote:But don't tell me you've been an avid PC gamer involved with gaming forums and haven't seen the phenomenon where with some people, every time their Zone Alarm or Norton beeps, they blame it on the game or the makers of third party addons. The same people that do that are the ones that will call you a hack if you disable their system keys.
Well, yes, of course, but thats people will complain for almost anything. It is truly valid to pursue the gratification of people that will complain anyway, against those who actually will try to focus?

Probably the best solution, and I absolutely agree with you is:
Quote:Make it an option that the user can turn on if they want.
That sounds like the perfect approach.

The anecdote about Office2k7 is hilarious. Im LMAO only by imagining the face of the guy trying to save the doc, with no gui for it. It is however, also a bit extreme on comparison; ctrl-S against the most widely known shorcut in history, like C-A-D? ;)
#13
02/17/2009 (5:29 pm)
Quote:"...crashed completely when the Windows key was pressed..."

LOL, another good idea!
#12
02/17/2009 (5:29 pm)
Quote:
It is truly valid to pursue the gratification of people that will complain anyway, against those who actually will try to focus?

If you think the added value is enough to offset the additional headache and potential loss of users/sales, then maybe not. It all depends on what you value I suppose.

Quote:
The anecdote about Office2k7 is hilarious. Im LMAO only by imagining the face of the guy trying to save the doc, with no gui for it.

Yeah, it cracked me up too :p


Quote:
It is however, also a bit extreme on comparison; ctrl-S against the most widely known shorcut in history, like C-A-D? ;)

Indeed, but still, a lot of people, including a lot of casual gamers, are point-and-click monsters and know no hot-keys. Some only know that the Windows key will minimize a full screen game simply because they have done it by accident before.

---

Actually, an ideal solution might be to detect when they use the Windows key, then minimize the game but popup a dialog telling them that they pressed the Windows key and they can check a box to have the game ignore the Windows key in the future, and another option to never show the dialog again.
#14
02/17/2009 (11:04 pm)
I didn't know this resource was going to have such a lively discussion O_o

Anyway, just fyi, this resource was created due to a requirement from the QA and design team, who felt that the windows key was not needed as the current game we are working on is an action game that is highly keyboard dependent and is mainly full-screen. As noted, everyone has different requirements so I do believe different solutions fit for different scenarios.

Quote:
Actually, an ideal solution might be to detect when they use the Windows key, then minimize the game but popup a dialog telling them that they pressed the Windows key and they can check a box to have the game ignore the Windows key in the future, and another option to never show the dialog again.
It is quite a good idea. Other variations also exist, such as sending the Window Key to be handled by the Torque event handler and let that be handled later :P

Anyway, I do stress, different situations, different requirements. The most important thing we have to remind ourselves that we have to find the best solution for our situation.
#15
02/24/2009 (8:31 am)
Quote:Nobody I know ever even uses the windows key, it's pretty useless. Unless maybe you have no mouse or can't find the "start" button lol.
The thing is actually pretty useful. I don't use it to bring the start menu up often, but it has a whole bunch of other uses (ordered in terms of usefulness).
+d brings you to desktop.
+e opens my computer
+r opens run
There are ones for minimize, maximize and a whole bunch of others, but I don't use those.
#16
02/25/2009 (10:06 pm)
If I might add a little to this as I came here as the title got my attention.

First let me address Novacks comments on gamers thinking this is a hack if you disable keys. I am one (Novack, sorry my friend:)). You start disabling keys for no valid reason other than your QA people have fat fingers (me included) you will loose trust. Let me explain why.

1. How many different keyboards and types of keyboards has your QA team evaluated? Was the Start key in the exact same location where a user could accidentally hit it? Or does the user have to go out their way to actually mess up and hit that.

2. If a user can hit Alt-Tab and switch programs why are your QA and design people worried about a user exiting the program in a way they feel comfortable with? If it crashes or causes problems hitting the Start, then it is going to have problems when they hit Alt-Tab.(BTW pressing my start key does not bring up the start menu if using a full screen app, it goes to desktop. Good feature to have if your boss walks up behind you:)


3. Do you realize how many different keyboards are out there?

Also, on the comments of avid gamers. I am one as well. At one point I had a custom made Aces II ejection seat just to fly flight sims. I had throttles and joysticks mounted on my chair to keep them from flying off the desk when I hit those high G manuevers.. oh sorry, got carried away re-living the past.

But that brings me to the last points I would like to throw out.

4. What Avid gamer uses a standard keyboard? I have two keyboards an ergonomic keyboard for regular work and a Z-Board I pull out for games (both are always hot).

5. Did your QA/design guys test how this works for keyboards that load their own drivers? You do realize that some keyboards load drivers first and will intercept the key anyway, thereby making all this time you have spent a wasted effort?

6. Did you test this on Vista and XP?

7. Did your QA/Design guys test to ensure this will not cause a crash instead on keyboards that load drivers, or where they just using their keyboards with the default windows drivers?

8. Why can I not reassign my Start Key that I us to fire my rockets? I mean I use it on all my other games (I am lying, just trying to push a point).


I know everyone has different requirements. But I subscribe to letting the users configure their own computer, including movement keys.

As far as casual gamers. If a game is so keyboard intensive that they spend more time trying to learn the keys, they will probably move away to another game. Casual gamers does not mean they don't know anything about computers, only that they have very limited time to play games. They want to get in and start having fun before they have to run that next errand... Not read manuals:)




#17
06/09/2009 (4:50 pm)
Good resource but it doesn't work perfectly for me.
The 1st time I push one of the Windows keys, it returns me to the desktop, then I go back in the game, and only now the Windows keys are disabled.

I use TGE 1.5.2 w/ Modernization Kit, and an Apple Pro keyboard in Win XP.

It seems like it does not work for any keyboard but Windows keyboards I guess.
#18
07/12/2009 (11:14 am)
@Yannick Lahay

Sorry, but I don't own an Apple Pro keyboard so I am not really sure about that issue.

Based on my own deduction, I think it is because the Apple Pro keyboard might send slightly different data to the keyboard for certain keys which might not be covered by the low level hook I wrote. Might need to slightly modify the low level hook based on the input received, though without the Apple Pro keyboard, I guess I really in the dark.