Error with combination Alt+Tab

Oct 31, 2011 at 8:19 PM
Edited Oct 31, 2011 at 8:20 PM

I try to set Globalhooker, when current active window is a game. When I switch to another window, the Globalhooker will be stopped and should be turn on again when I switch back.

Everything functioned properly, when i switched to another application with LeftWin or RightWin. I get an error, when i pressed combination Alt+Tab : after that I can not take keyboard control when out of my game !?!

In particular when i playing, I pressed Alt + Tab to switch applications, after that i can not type with keyboard more characters (including in game). Then i must press Ctrl + Alt + Del to end it. I use Win 7 64bit.

I don't want to disable Alt+Tab, I just want it will work properly.

Any idea ? Thanks for the answer !

Coordinator
Oct 31, 2011 at 8:46 PM

How are you disabling and reenabling the hook?
Are you getting an exception? Which one if yes.

What is the code inside event? How time consuming is it?

Please post appropriate code snippet.

Nov 1, 2011 at 1:39 AM

I'd also like some more information, if you don't mind.

Are you sure your conditional logic is correct? It might be as simple as that.
What game is it?
Are you only trying to prevent Alt-Tab (or WinKey) while you're in-game to prevent minimize?

Games that use DirectX (or applications that use DirectInput) sometimes act screwy with callbacks, especially if that game has administrative permissions and your global hooker does not.

If you're trying to prevent Alt-Tab (or WinKey) when the game is focused, and not just active, look into the GetForegroundWindow() Api. I used a very similar method for a game cheat once, and it worked quite well.

Nov 1, 2011 at 2:02 PM
Edited Nov 1, 2011 at 2:50 PM
PyrrhicVictor wrote:

If you're trying to prevent Alt-Tab (or WinKey) when the game is focused, and not just active, look into the GetForegroundWindow() Api. I used a very similar method for a game cheat once, and it worked quite well.

Yes i used it.

Here is my source code : I creat a Timer running at the speed of 1ms, I test every tick of Timer with the GetForegroundWindow() method so as to know whether the title of active window is my game (Warcraft III) or not. If yes I'll active the Globalhook, if not ignore it (or then disable if Globalhook is active). I try to use this way to switch among applications by LeftWin và Rightwin, they all work fine !!

But when switching by Alt + tab I lose the control of keyboard (can't type with keyboard) after swithching from my game to another software or programs, hence I must to press the combination Ctrl+Alt+Del, it then switchs to task choosing table (Lock this computer, Lock off, Switch user etc...) I only have to press Cancel and control of keyboard reworked !?! I use Win 7 64 bit

Sorry for my bad English :(

PS: I think that the problem is related to Left Alt key (LMenu). It is the difference between  LeftAlt + Tab and RightAlt + Tab...

Nov 1, 2011 at 3:18 PM
Edited Nov 1, 2011 at 3:21 PM

Your English is fine. Much better than my French. =)

Having a timer run every 1ms is overkill. If you must use a timer, increase the interval to a minimum of 50ms, but I recommend 100ms.

When you say that you activate GlobalHook, do you enable it or create a new instance?

Honestly, it would be much easier to know what the problem is, and possibly if its a bug in the library if you'd post the code of the KeyDown handler.

Nov 1, 2011 at 10:41 PM

Thanks for the advice with the Timer. It helped me a lot !

Finally I solved it. The error was in logic algorithms :( I think your library works great and flawlessly.

Sorry about that i bother you all the time :(