disable windows key - hook or message pump?

Started by
6 comments, last by Norman Barrows 10 years, 1 month ago

disable windows key - hook or message pump?

can the windows key be trapped via the message queue, or must one use the keyboard hook?

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

Advertisement

As far as I know it has to be done as a keyboard hook. ALT and F10 can be handled with the usual message pump though.

Why not just pause your application when the user switches?

Even the Elder Scrolls Online beta (which can't be paused, obviously) was quite happy switching between apps, which can be really useful from a users/developers perspective.

There different meanings of disabling the windows key.

If you are building a kiosk-style program you can disable it through various methods, and also modify the system so the key event gets handled by your application. That probably isn't what you are talking about, but just leaving it out there since it meets your wording.

For games, be very cautious about disabling any system-level functionality. It can go far beyond just confusing your users, it can make them very angry.

There are some games where players use alt as a hotkey, use tab as a hotkey, and are occasionally bumping alt+tab together and accidentally swapping applications. There are some games where players are rapidly pounding on the keys around the start button and accidentally bump the key. If you want to prevent access on those keystrokes make it a highly visible option so players know how to disable your feature. StarCraft 2 is a great example of this.

You can accomplish the technical side by consuming the WM_SYSKEYDOWN and WM_SYSKEYUP events that correspond to the specific event you want to prevent. In addition to alt+tab, you may want to capture VK_LWIN, VK_RWIN, and VK_APPS.

I have never found an alternative to keyboard hook - although i have never wanted to disable it per-se, just disable its usual function and make it available as a regular key for keybinds.

However, as frob mentioned - have an easy to access option for disabling the override.

OT: Similarily, might want to consider optionally disabling sticky keys etc whenever your game has focus (you can do that with SystemParametersInfo). Specifically: STICKYKEYS, TOGGLEKEYS and FILTERKEYS.


Why not just pause your application when the user switches?


There are some games where players are rapidly pounding on the keys around the start button and accidentally bump the key.

that's why. <g>.

Caveman does support full task switching now. Even gets the windows mouse cursor correct, which Skyrim doesn't.

but its also a game where one can accidentally hit the windows button (start menu button) in the heat of combat.


You can accomplish the technical side by consuming the WM_SYSKEYDOWN and WM_SYSKEYUP events that correspond to the specific event you want to prevent. In addition to alt+tab, you may want to capture VK_LWIN, VK_RWIN, and VK_APPS.

I suspected as much. why mess with the low level hook, when you already have to process the incoming messages anyway, and can just intercept them there.

I do not plan to disable alt-tab. only the windows key. the apps key would probably be a good idea too.


OT: Similarily, might want to consider optionally disabling sticky keys etc whenever your game has focus (you can do that with SystemParametersInfo). Specifically: STICKYKEYS, TOGGLEKEYS and FILTERKEYS.

yes, i found that too during my online search. in that case, i find its VERY rare that one accidentally triggers sticky keys. if one does, a menu pops up, you simply turn them off, then alt-tab back to the game. i don't think this rare special case needs anything more than that. also, users who actually use such features should be used to having to turn them off to play games.

i'd prefer to disable as little as possible - leaving it to the user to explicitly disable incompatible software (like sticky keys) BEFORE launching the game.

but things like the windows key could really use a disable option - its just too easy to press it accidentally in combat - depending on keyboard layout of course.

here's MS's official web page on the subject....

Disabling Shortcut Keys in Games:

http://msdn.microsoft.com/en-us/library/windows/desktop/ee416808(v=vs.85).aspx

but this only describes the hook method, and the stickykeys etc method. the message intercept method is described in various threads about the subject here on gamedev.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

I would be weary of capturing any default system functionality in an attempt to disable or prevent it's actions. I've played games that have done just this and find the behavior intrusive and having no merit. Users should be capable of using their systems as they see fit and it should be their responsibility to make intelligent decisions about bindings, button usage, etc that maximizes their own play style that they find effective; not the game itself.

The best middle ground IMO would be that if you wish to offer such a feature, be sure to make it something that the user can toggle ON/OFF depending on their preferences in some game menu screen. This way, those who fall into the category of hitting the button mid-combat have a reprieve to their mistake while those who want to keep the default button functionality available can do so.

yep, option to disable windows key sounds like the way to go.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

This topic is closed to new replies.

Advertisement