Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Disabling Alt + F4

Author
Message
SamKM
15
Years of Service
User Offline
Joined: 25th May 2009
Location:
Posted: 30th Jun 2013 01:07
Hey
Just wondered, is there a way to disable alt + f4 in Darkbasic Pro? I know that's one of the things that 'disable systemkeys' is supposed to do, but from what I understand that command is pretty useless on modern systems :/
It's just I'm pretty sure I've played at least one FPSC game where I've tried using Alt + F4 to quit, and nothing's happened... So it must be possible somehow in Darkbasic, right?
Thanks
Indicium
16
Years of Service
User Offline
Joined: 26th May 2008
Location:
Posted: 30th Jun 2013 01:24
Why would you want to disable it unless you were doing something malicious?


They see me coding, they hating. http://indi-indicium.blogspot.co.uk/
SamKM
15
Years of Service
User Offline
Joined: 25th May 2009
Location:
Posted: 30th Jun 2013 01:58 Edited at: 30th Jun 2013 21:33
Good question
I can't blame you for thinking I might be up to something malicious... Actually, I'm trying to design a horror game which tries to break the 4th wall as much as possible, and make you believe your computer has been taken over... There are a couple of points where some people might freak out and want to quit, and it'd be awesome if they didn't have a way of doing it...
Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 30th Jun 2013 02:51 Edited at: 30th Jun 2013 02:52
It is done in AAA PC games; Alt F4 may even be binded to a game action.

The only valid procedure for allowing the user to Alt F4 out of a video game is if your program listens to the windows message and shuts itself down properly instead of just being terminated abruptly by the operating system whilst the game could be accessing delicate files on the hard drive, or transmitting important information.

Otherwise you should disable it if you feel an abrupt termination is un-safe.

As for a solution, use BBB GUI (Visit the WIP board). Run the Window example, that shows you how to listen to window close events. Just check if Alt and F4 is down when the window close event is received then prevent it from closing if the game is busy; otherwise display an option message; as is done in the example.

wattywatts
15
Years of Service
User Offline
Joined: 25th May 2009
Location: Michigan
Posted: 30th Jun 2013 04:10
I'd be pretty pissed if I couldn't exit a game, personally.

http://mattsmith.carbonmade.com/
JackDawson
13
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 30th Jun 2013 04:46 Edited at: 30th Jun 2013 04:48
IS this what your after ?

some of the code grabbed from the help in DBPro.

Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 30th Jun 2013 05:12
Quote: "I'd be pretty pissed if I couldn't exit a game, personally."


I know what you mean; but you can exit the game with just two mouse clicks, or a tap of the escape key followed by the return key. As a programmer you'd understand how important it is for the program to not exit before saving game data. This is why such games minimize into the background when you exit to perform a clean up and save your latest game data to disk.

Better to exit it properly with two commands and have your system intact, than to exit it with one command and end up with zero game data.

Quote: "some of the code grabbed from the help in DBPro."


Yes, that is also a solution.

Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 30th Jun 2013 05:30
Quote: "As a programmer you'd understand how important it is for the program to not exit before saving game data."


Alt-F4 is a 'last resort' type of thing when you need to forcibly terminate the application; it's not used to exit a game normally.

"Sideboobs are awesome. Getting punched in the face is not." - Jerico2Day on violence and nudity
Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 30th Jun 2013 06:03 Edited at: 30th Jun 2013 06:09
Yes, that is where design preference comes in. In one engine such as Valve Source, you cannot press ALT-F4 to exit; but you can ALT-Tab back into Windows; and with other engines it is the other way round.

With design preference you might prefer that the user ALT-TAB then close the program so that the customer will not accidentally press ALT-F4; or for some reason you might not care if the customer accidentally presses ALT-F4; and the customer who does it might not care about restarting that level over again.

The likelihood of this happening depends on the amount of players, how long these players play. With just 10,000 or so players in a small game, maybe it would only happen once and a while. The severity falls down to how difficult it would be to restore what was lost.

wattywatts
15
Years of Service
User Offline
Joined: 25th May 2009
Location: Michigan
Posted: 30th Jun 2013 06:13
Quote: "As a programmer you'd understand how important it is for the program to not exit before saving game data."

I know, and I'm with you, but he said
Quote: "some people might freak out and want to quit, and it'd be awesome if they didn't have a way of doing it"

Which leads me to believe he wants to do everything possible to make it impossible. Maybe I'm reading it wrong.

http://mattsmith.carbonmade.com/
JackDawson
13
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 30th Jun 2013 06:19
I always add my own exit strategy to my software. I disable the ALT-F4 and I use the DBPro disable escapekey command and I make my own escape key exit menu to prevent game data corruption. I also use the is focus() function from matrix1 DLLs because that way if I ALT-Tab out, I can then still get out and not have to worry about my mouse not showing up. That is an easy fix as well by writing a function to keep and eye on it. While tabbed out, I can still keep the game running. I can then properly shut down the game at this point if I so choose.
PirateJohn
13
Years of Service
User Offline
Joined: 4th Aug 2011
Location: California
Posted: 2nd Jul 2013 02:09
Just remember that the biggest reason that people use Alt-F4 to exit a game quickly is not because they're scared of your game, but because they're scared of their boss walking around the corner.
GIDustin
16
Years of Service
User Offline
Joined: 30th May 2008
Location:
Posted: 2nd Jul 2013 03:23 Edited at: 2nd Jul 2013 03:28
I remember the old WoW days...

Noob: How do you select your Glyphs?
Punk: Hold Alt and press F4

If you have Matrix installed:



Edit: The advantage to this method is you are able to respond to their "exit" request remind them to save their work (or taunt them in the above case)
Burning Feet Man
17
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 2nd Jul 2013 05:07
Exactly. There are all sorts of valid reasons why you'd need to know if your application is being exited.

I'm so tired of reading first posts such as these;

Quote: "Why would you want to disable it unless you were doing something malicious?"


Why bother even asking why? Having the assumption of malicious code is just lame! Do you think that someone visiting "The Game Creators" forum is going to write the next Stuxnet with DBPro, and that their master plan all comes down to knowing how to disable ALT F4?

LMFAO.

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
Mage
Valued Member
18
Years of Service
User Offline
Joined: 3rd Feb 2007
Location:
Posted: 2nd Jul 2013 09:00 Edited at: 2nd Jul 2013 09:04
When programming .net applications, I always found the form functions that are event based and run when the user tries to close the window to be really helpful.

I wrote a program that displays a picture album and lets you click zoom all the photos from a collage layout.

The program is able to save a list of all of the photos and information matching them to cached thumbnails when the program closes.

I also wrote a windows network file-sharing application for my friends and I on our huge university campus network. It crawls the entire network recording all files. Hundreds of thousands of files, and the app has a search/download/filetransfer interface. So some computers aren't online all the time, you can set it to download a file when it comes available automatically. It saves all this list data to the hard drive when the app is closed.

So I can see the use in temporarily intercepting or controlling the exiting of an application. But its really easy for a crappy programmer to make a terrible application with it. It's generally not needed for a video game. But might be more commonly useful for an editor made in DB Pro. Or maybe a windowed game, like solitaire for saving history.

Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 2nd Jul 2013 09:45 Edited at: 2nd Jul 2013 10:02
I love my PC too much to ALT-F4 out of anything resource intensive.

At work, who cares about the Boss's PC; but on your own system? You've just gotta have some love and appreciation for your system.

I'm glad this thread was made, this brings a number of thoughts in my mind

One, the customer will try to ALT-F4 regardless of what data is being written in the background or left decrypted or uncached. And what on earth makes people think something else didn't shut down when the program terminated that was supposed to be shut down...

Two, the customer will also ALT-F4 out right before loosing a game so that the game loss isn't transmitted to the server.


Quote: "Quote: "some people might freak out and want to quit, and it'd be awesome if they didn't have a way of doing it"
Which leads me to believe he wants to do everything possible to make it impossible. Maybe I'm reading it wrong."


Not being able to quit would be real funny. Print on the screen the following: "No! You may not exit; it is your time for doom!" They'd have to turn off the sound and the monitor and run away.

Quote: "When programming .net applications, I always found the form functions that are event based and run when the user tries to close the window to be really helpful."

Quote: "
I always add my own exit strategy to my software. I disable the ALT-F4 and I use the DBPro disable escapekey command and I make my own escape key exit menu to prevent game data corruption."


That sounds like what I am doing. There is a reason why Microsoft created the window close event.

Anyway, most video games that are performing any delicate operations with the hard drive, RAM or GPU will ignore ALT-F4 until the operations are complete.

One thing that does tick me off is a game with no allowance of ALT-TAB window switching; so you must exit the game to check an email...

Ohh.. and the games that hide the mouse without any close event handling; then when you terminate it, the mouse is gone; bye bye mouse, must restart PC.

Pincho Paxton
22
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 2nd Jul 2013 12:35
I didn't even know about Alt F4.

RonsWare
14
Years of Service
User Offline
Joined: 5th Sep 2010
Location: Netherlands
Posted: 2nd Jul 2013 13:06
I never use Alt F4.

Cheers Ron.

Programming is learning
JackDawson
13
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 2nd Jul 2013 13:52
Quote: "I never use Alt F4.

Cheers Ron."


Same here. And I wouldn't play a game at work and try to hide it from the Boss anyhow. I value my job too much. Work is scarce.
wattywatts
15
Years of Service
User Offline
Joined: 25th May 2009
Location: Michigan
Posted: 2nd Jul 2013 20:45
MGS2 on PC had a problem on certain computers where pressing escape would fail to bring up the exit game menu, so the only option to exit would be ctrl+alt+del or alt+f4. If they would have blocked these, many players wouldn't have been able to exit without rebooting. I just think it's a bad idea.

http://mattsmith.carbonmade.com/
Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 2nd Jul 2013 21:15 Edited at: 2nd Jul 2013 21:17
Quote: "MGS2 on PC had a problem on certain computers where pressing escape would fail to bring up the exit game menu....many players wouldn't have been able to exit without rebooting. I just think it's a bad idea."


That is a bug; that is something that is not supposed to happen, and so your data is likely lost by this point anyway so exit handling won't help since there is no exit handling available; so the solution is to ALT-TAB and close it.

Wow that is one ghetto buggy video game. So all the other buttons work; except the escape button? That would be like the shut down button on windows not working. How difficult could IF EscapeKey() Then ShowExitMenu() be for a modern PC game; that event handler must be a cowboy job or something.

I can understand why you think it is a bad idea now; I've never experienced what you have mentioned in commercial game. I would always be able to ALT-TAB and shut down the game. That is just so... poor quality.

Even in my test DBPRO projects I can ALT-TAB and exit.

As for commercial game exiting it works the other way round; the game closes itself without me telling it to.

This is no joke; at least twice a week Valves Counter Strike GO exits and restarts itself midway through a match. It exits, then you think 'what the?', then on comes the loading screen, 'starting Counter Strike Global Offensive'. Sometimes I turn the PC on, then run it and it says 'The game is already running', so I run it again. So even at the top there are some really buggy programs out there, all the more reason to be cautious.

SamKM
15
Years of Service
User Offline
Joined: 25th May 2009
Location:
Posted: 2nd Jul 2013 23:12
Haha, thanks for all the replies everyone!
I should probably say, I totally agree not allowing the player to exit the game, and forcing them to stay in it is in 95% of circumstances NOT a good idea for PR
Apart from when a program is doing something sensitive with it's/your data, as people said
Just to give you more background as to why I wouldn't want people to exit, this idea behind my game is there is supposedly a malicious entity that haunts this game, and then your computer once you've taken the risk of running the game (it's actually based off a creepypasta story)... Obviously, it doesn't actually take over your computer, or it'd be a virus, but it tries to create the best illusion of this possible, and somebody simply being able to quit this game half way through isn't something this entity would allow you to do... So it would kind of break the illusion
Thank you for all the suggestions, I'll try them soon
Dar13
17
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 2nd Jul 2013 23:14
Quote: "I love my PC too much to ALT-F4 out of anything resource intensive."

You do realize that Windows releases all resources when the application is closed? The only damage that could occur is file corruption if the application is actively writing to disk. And in that case you just throw a simple "When you see this icon, don't turn off your system or quit the application" warning like you see in most games these days.

In all honesty I don't particularly care if Alt-F4 is disabled as long as I have Ctrl-Alt-Del. And if a game disables that, especially when the game is a buggy mess that freezes or crashes a lot, I get angry if I have to resort to a hard reset because of somebody's crappy and inconsiderate coding. Now that is an action that could damage your computer if you do it enough times.

WTLD has been put on indefinite hold.
A new project is under initial development now.
Chris Tate
DBPro Master
16
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 3rd Jul 2013 01:57 Edited at: 3rd Jul 2013 02:20
Quote: "You do realize that Windows releases all resources when the application is closed?"


Come on, are you having a laugh? I'm not that retarded you know.

Quote: "The only damage that could occur is file corruption if the application is actively writing to disk."


That is the central point of the argument.

Quote: "
In all honesty I don't particularly care if Alt-F4 is disabled as long as I have Ctrl-Alt-Del. And if a game disables that, especially when the game is a buggy mess that freezes or crashes a lot, I get angry if I have to resort to a hard reset because of somebody's crappy and inconsiderate coding. Now that is an action that could damage your computer if you do it enough times."


Very true.

Quote: "WIKI: Table of keyboard shortcuts: Close the focused windowAlt+F4 or Ctrl+F4 or Ctrl+W or Alt+Space"


Some other close window commands; notice how it is for closing the focused window, and not the program; it is up to the program to decide what to do if the main window receives a close event. You even get a cancel close return option in windows forms applications.

Quote: "I totally agree not allowing the player to exit the game, and forcing them to stay in it is in 95% of circumstances NOT a good idea for PR"


There has been a misunderstanding of what I was recommending;

The player should be allowed to exit when they want.

I do not recommend NOT allowing the player to exit. That is quite bizarre really. Reminds me of wanting to shutdown Windows and switch off the PC before the electrician switches off the power, oh wait Windows needs to install 103 updates.. (Ok you can disable that feature, but you get the point)

What I was recommending is to disable the operating system from ending the process without it closing properly; IE handle the exit event, hide the window, finishing saving to the disk, then end the background process.

A bit like what your web browser does; when you ALT-F4 out, it hides the window, shuts down and saves the session, cleans up the cache then terminates the process. It doesn't just end straight away like that, it handles the exit procedure; rather than letting the OS terminate it. That's what disabling ALT-F4 is for, to handle the exit procedure yourself.

Anyway, it will all make more sense when you actually create a program that accesses lots of files.

Dar13
17
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 3rd Jul 2013 06:44
Quote: "Come on, are you having a laugh? I'm not that retarded you know."

Nope. Windows takes back all memory used by an application when that application terminates. That's why having a program like this in C/C++, while lazy, is ok and won't damage your computer/OS:


Pseudo-source that I could find quickly, I had read somewhere on StackOverflow that answered this question specifically but I can't find it.

Some other comments that say the same thing:
http://stackoverflow.com/a/276806/1287421
http://stackoverflow.com/a/242317/1287421

WTLD has been put on indefinite hold.
A new project is under initial development now.
Mage
Valued Member
18
Years of Service
User Offline
Joined: 3rd Feb 2007
Location:
Posted: 3rd Jul 2013 09:53
Quote: "Nope. Windows takes back all memory used by an application when that application terminates. That's why having a program like this in C/C++, while lazy, is ok and won't damage your computer/OS:"

I can confirm this is true. I didn't mention anything because I didn't realize he really thought the opposite.

The windows kernel manages all of the memory using a protected paging system.


I think the best arguments for disabling alt + f4 have been to make sure the game saves before exiting (like an IOS game) and to properly disconnect from multiplayer. These can be achieved by disabling ALT+F4 and emulating it. So create a function like this:



Then in your game loop you can add a line to detect ALT + F4 and handle it manually like this:



You'll need to have ALT+F4 disabled of course in order to handle it's function manually like I am suggesting.

Login to post a reply

Server time is: 2025-05-20 17:58:21
Your offset time is: 2025-05-20 17:58:21