Game Development Community

Request: Allow me to bind Alt+Tab

by Novack · in Torque 3D Professional · 05/05/2009 (11:58 pm) · 8 replies

//this works
GlobalActionMap.bind(keyboard, "alt enter", myBindTest);

//this doesn't work
GlobalActionMap.bind(keyboard, "alt tab", myBindTest2);

Everytime the game lose its the focus, I want to do some tasks, like pausing the game, and redrawing some parts on getting it back.

As described in the example script, Alt+Enter works, Alt+Tab doesn't.

#1
05/06/2009 (2:06 am)
I had a similar issue with another keyset and another application but i think it still applies.

Theres a bunch of commands in the OS that are kept sacred by the OS makers, along with the hotkeys for those commands, i'm not saying that they are impossible to remap but the OS makers make it difficult.

And for good reason in some cases, PC users 'expect' certain things to happen, if they dont they phone tech support :p
#2
05/06/2009 (2:35 am)
I take it your a Mac person? (just an observation not a judgment)

If that were how it is, then in this case alt enter should not work either.
#3
05/06/2009 (2:38 am)
Probably should try to hook in some script callback when game loses focus instead of trying to rebind that input, which is like Bloodknight said some OS specific commands.
#4
05/06/2009 (2:52 am)
If i rememeber correctly this issue is more complex than it seems... at least it was some years back when i last looked at it.

DirectX never gets the Alt+Tab keyboard event... the OS grabs it and starts switching focus.

There are articles out on the web on how to subvert the Alt+Tab request and keep the application from switching if thats what your really after.

If we can work out a simple feature along those lines i would be willing to merge it as an optional pref.
#5
05/06/2009 (9:17 am)
Thanks for the sugestions guys.

@Tom, Im not really after stoping/changing the SO use for that matter, but adding a task to it in the queue. I dont have a problem with the user switching applications by alt-tabing, what I need is to know when he does, so I can also take action (like said, pause the game, and redrawings).

In the end, may be as suggested, not looking into alt-tabing but the game focus.
#6
05/06/2009 (9:26 am)
Ah, then you want to hook into GuiCanvas::onLoseFocus and GuiCanvas::onGainFocus, those do exactly what you want. By the way, torque already does certain things to reduce cpu usage when the app doesn't have focus.
#7
05/06/2009 (9:27 am)
Look at the Engine/source/app/mainLoop.cpp inside bool StandardMainLoop::doMainLoop()
You can add Con::executef to call scripted functions like "onFocusLost" or "onFocusGain" so you can track down that even by using alredy-built engine-functions.
At the same place engine changes getBackgroundSleepTime already, so it could be right place for scripted event.

edit: oops, James already posted similar way of handling that :)
#8
05/06/2009 (9:36 am)
Thank you very much fellas.