Detect Alt+Tab
Miscellaneous Forums/General Discussion/Detect Alt+Tab
Howdy, sure this has been asked before but I'll ask again.
Is there a way to detect alt+tab in your full-screen blitz app, not so you can disable it (I know how to do that) but so that when the user eventually comes back you can restore all the corrupted dynamic images (i.e. BackBuffer and images created with dynamic flag)? In fact the problem is not so much as detect alt+tab but detect when you app "regains" focus after an interruption.
Any ideas?
Thanks
You should be able to do this both by looking for the keyboard hook of alt-tab and also, in a better method, checking the active window, this is done in ... um, I think it's user32.dll.
Personaly I cant be hashed with all that, if someone wants to check their emails when playing one of my games then they're clearly not interested enough to stay playing for much longer anyway.
Nice attitude, Becky. It's their PC, they can to whatever they want to with it. I'm guessing you've never released a game commercially? :)
I assume you're talking about B+
; .lib "user32.dll"
; GetActiveWindow%()
Graphics 640, 480, 16, 1
hWnd = GetActiveWindow()
Local bGone = False, ret = False
AutoSuspend 0
While Not KeyDown(1)
If ret = True Then Text 1, 1, "I have returned!"
curhWnd = GetActiveWindow()
If curhWnd <> hWnd Then bGone = True
If curhWnd = hWnd And bGone = True Then bGone = False: ret = True
Delay 10
Flip: Cls
Wend: End
B3D doesn't have an autosuspend switch, so I couldn't get it to work fullscreen.
It depends on the game. Like, during Solitaire it's perfectly normal for people to check their email during the game (or rather, people play the game while waiting for email,) but for an FPS I think it's fair to say the person has to quit the game in order to use other apps.
Incidentally, how do you disable Alt+Tab? That could be useful to know.
Nice attitude, Becky. It's their PC, they can to whatever they want to with it. I'm guessing you've never released a game commercially? :)
You guessed wrong. The thing is, there's all sorts of things that can interfere with gaming experience that you just cannot account for.
Do you only use colours that contrast well for certain colour blindness conditions? Alpha Centuri released a patch for the colour blind...
Do you fade time out/in when pausing to allow players to better pick up where they left off without error, or do you let people rush to the phone?
Do you enable escape on exit so people can exit your game quickly, and get a complaint about it as I did from somebody who pressed it accidentaly?
I just feel it's better to focus on the game, not the quirks of end users. Then if somebody wants a specific feature added to compensate for their playstyle, disability etc decide if they where polite enough to add it for them.
You guessed wrong.
Care to name a commercial game you've done? Not disputing you've done one, just interested. ;)
Do you only use colours that contrast well for certain colour blindness conditions? Alpha Centuri released a patch for the colour blind...
I would if colour was an integral part of the game... probably.
Do you fade time out/in when pausing to allow players to better pick up where they left off without error, or do you let people rush to the phone?
Rush to the phone? I don't understand.
Do you enable escape on exit so people can exit your game quickly, and get a complaint about it as I did from somebody who pressed it accidentaly?
An "Are you sure you want to quit?" is the widely used method, I believe. :)
...My God, I think I'm turning into FlameDuck! NOOOooooooo
Eikon: That is EXACTLY what I wsa looking for you are a star! I shoulda worked it out as I already use GetActiveWindow.
Becky: This will be a commercial game. I alt+tab from full-screen games for a number of reasons a) I'm debugging it for someone and want to make notes in Word doc, when I return I don't want the graphics all messed up b) I want to check a walkthrough that I have saved on my PC c) I want to download a walkthough! d) any other misc stuff to be honest. I normally pause by going to the menu and then alt+tab there. Games that block it are limiting my use of a Windows PC. When I originally coded my game I avoided using dynamic images and redrew the backbuffer every frame thus didn't need this code. Now I have implemented a quintuple buffer dirty rects system so it runs on slower machines I am having to use dynamic images plus the backbuffer is NOT redrawn every frame, only portions of it are, thus alt+tab corruption becomes and issue again.
Becky: The big commercial app I've been working on for years has a user-definable colour scheme and a colour blind mode and a b+w mode (plus all manner of other stuff/crap). In my game have a pause function (and music stops) but no fade time out/in when pause toggled, I've only seen this once actually in all my years, good idea. Escape shows the in-game menu on mine (and escape hides it) but I do have Ctrl+X for quick exit (i.e. no accident) plus B = boss key which changes to windowed mode and minimises. Also music and gameplay stops when minimised, not all games do this! I got the game up and running ages ago and worked out how to do all this stuff at the end so it is Pro not amateur, then all the code can be reused in future projects. Other normal features exist like music/sound on/off (+user can set volumes) and 16 bit mode and even a Flip False/True option.
btw does anyone know if not redrawing the backbuffer every frame in BlitzPlus is an issue because in the BlitzMax docs it says you should cls it and redraw everytime as it's not gauranteed to stay the same or something. I figured this was probably just an oblique warning to the alt_tab problem but does the backbuffer ever get destroyed in game by anything or by crappy video cards? Seems OK on my PC and other test PCs though.
jhocking: Blackjumper has a .dll in code archives called Stickykeys.dll it does lots of things inc. disable alt+tab, it's really rather good!
Big10p: She's just gonna say look at her website.
I should have realised you'd ask when I said that, I have tried hard to avoid giving specifics of my background around here - I meant only to point out not to suppose anything :). Anyway, I never said I have had a sucessful game and when you think about it, most of the people on here have done a "commercial" game of some form.
I think in recent years shareware/commercial status has blurred quite a lot. There's still a divide as far as shops are concerned, but i'm no longer convinced shop sales of latest games represent the largest market share.
hmm some confusion here, surely commercial just means you are selling it i.e. it's not freeware or unfinished or unreleased. I would include shareware in commercial too as well as downloaded games and shop sold games.
"but i'm no longer convinced shop sales of latest games represent the largest market share" They do, there was some stat about downloadable games being only 10% of the market recently BUT it's growing.
I should have realised you'd ask when I said that, I have tried hard to avoid giving specifics of my background around here
Why? Are you ashamed of your past games, or something? I really don't understand this.
And my definition of 'commercial' is the same as Grey's. I don't see any commercial games on your website. In fact, you don't seem to be listed in the profiles. C'mon, spill the beans. :)
>>downloadable games being only 10% of the market recently BUT it's growing.
That's interesting, it's easy to get figures for shop sold games but much harder to account for shareware sales, especially as there is such variety in the industry - Blitzers like IPete2 for instance make 1 sale, but that 1 sale is worth a small fortune - how do you rate it? I wonder just how many niche's where covered in that estimate, or even known to the surveyors?
stats are stats at the end of the day but it's fairly obvious the market is growing and thus I'm in it!
Hmmm. No comment, huh?
I smell BS. :)
Maybe you can't handle the truth :).
Show a link to a game you've sold.
Eikon: ACE. implemented as easily as this, where UserGone and TheWindow are global:
Function DetectAltTab()
If IniWindowedMode Then Return 0 ;not relevant
Local curhWnd = User32_GetActiveWindow()
If curhWnd <> TheWindow Then UserGone = True
If curhWnd = TheWindow And UserGone = True Then
UserGone = False
;redraw the screen
If CurrentScreen = scGAME Then AppScreenDrawMain(1) ;and copy to buffers
EndIf
End Function
Thanks! Another step towards "pro"dom.
Becky: I know you worked with Commodore for years and that website you've shown before (something games) has games on it but can't see your name anywhere obvious. Did you work on those?
Anyway don't argue over that poop, I posted some interesting stuff about MY game ;-)
I've been in and around the programming business the best part of my life, we didn't always have the internet.
Anyway, why should I? To satisfy the curiosity of a few potential flamers? My point was merely not to make suppositions of what i'd done, not to say "I art better than thou".
The debate, despite this branch of the tree, was actually about whether it is necessary to account for all of the possible non-related things which can occur during games (at least, that was the debate after GA got his answer)
My thoughts on the subject are that there's so many things that can "go wrong" and occur outside of the game that patching up one possibile circumstance doesnt touch the ice berge, so why try?
Of course to an extent this depends upon the game, if we're talking solitaire then alt-tab makes perfect sense.
Yeah, sorry for hijacking, Grey, but you did get your answer. :)
Just... one... last... go...
Maybe you can't handle the truth :).
I'm a big boy now - I can handle it. Don't keep us in suspenders! :) If you'd done anything THAT amazing, I'm sure I'd already know about it. ;)
Well I think that some things are much more likely to happen and are worth patching (to prevent a million Helpdesk calls) and others less so, so sure forget them until enough users moan. Actually this has been my business practice for 9 yeats and it worked for us.
@Grey Alien: Nice work on the function, I am happy to have helped :)
@ Grey Alien:
Thanks for the kind words about Sticky_Key.dll
It seems to have made its way into a number of Blitz stuff released recently.
An update is planned that will have some information function calls in addition to much more precise control over which parts are allowed/blocked. A call like GetLastSystemKeyCombo$() will tell you whether Alt+TAB or Ctrl+ESC (etc.) was pressed. The event will be reported whether it was blocked or allowed by Sticky_Key.dll
I am also hoping to get W98SE support working so that big10p can play too.
I had hoped to get that done during school half-term (end of October) but went to Amsterdam instead :-)
BlackJ: pleasure, new version sounds cool esp with Win98 support if poss.
I am also hoping to get W98SE support working so that big10p can play too.
:)
BTW BlackJumper, have you seen
this in the code arcs, specifically the link Perturbatio posted at the bottom? I expect you've already read that info but I thought I'd let you know, just in case. ;)
On a related note: Keep in mind that there are many other keys in addition to ALT-TAB to think about as well!
For example:
- Left-windows key (app will switch to desktop after you let go of it)
- Right-windows key (app will switch to desktop after you let go of it)
- CTRL-ESC (which opens the windows Start menu)
- Many of the custom-keys on 'office', 'multimedia' or 'internet' keyboards will launch custom applications and switch to the desktop while doing so.
xlsior Yeah, don't worry I've been a windows programmer since 1996, Ctrl+Esc was for non-windows (102-key) keyboards, remember those? Your code snippet handles all those as they just cause a lost focus. Also BlackJ's code handles the windows keys and ctrl+esc but probably not the shortcut keys, that's just tough I guess.
[edit] damn and blast, windows key (and Ctrl+Esc) don't launch any apps so the window doesn't loose focus and thus the graphics corrupt and aren't restored. Maybe the window is counted as minimised though, I'll check.
Yup the window is in minimized state thus some existing code I had already works, just added in the restore graphics and woo, it supports all kindsa crappy interruptions now. This is cool:
Function DetectMinimize()
;Should we pause or restart the music
If Not Minimized Then
If ccGetWindowPlacement(TheWindow) = SW_SHOWMINIMIZED Then
;were we already minimized?
If Minimized = 0 Then
Minimized = 1
If IniMusic Then PauseChannel(GameMusic)
;Don't need to touch the Close Handler
EndIf
EndIf
Else
If ccGetWindowPlacement(TheWindow) = SW_SHOWNORMAL Then
;were we already normal?
If Minimized = 1 Then
Minimized = 0
If IniMusic Then ResumeChannel(GameMusic)
;Don't need to touch the Close Handler
;If fullscreen we must have been forcefully minimised by
;windows key or ctrl+esc or alt+tab so redraw game screen
If Not IniWindowedMode Then
;redraw the screen
If CurrentScreen = scGAME Then AppScreenDrawMain(1) ;and copy to buffers
EndIf
EndIf
EndIf
EndIf
End Function
[edit] just to be clear ccGetWindowPlacement is a User32 function that needs to be added to User32.decls.
Cool beans.
If anyone wants to list all of the possible shortcut interrupts I can code around them in the next version of Sticky_Key.dll
Please post any shortcut disable requests
here{I have cross-linked to this thread there}
@big10p:
Thanks for the heads up on Seb's Hotkey solution to Alt+TAB... the research I did suggested that it wasn't very reliable for W98, etc. so I am aiming for something more robust.