I am creating a game and i want that if the user hit F10 or any other function key then they the program should end.
How to exit a gw basic program at any time?
5.5k Views Asked by Naushaad Abbas AtThere are 4 best solutions below

I assume you are in the middle of some kind of BASIC program and you would like to 'get out', exit from this ?
Press ENTER
to get to a BLANK space and type system
, hit ENTER
again and you are out!

For future searchers, this answer provides additional context to inform the design of mechanisms for exiting BASIC programs.
For some simplistically designed BASIC programs, the only method to exit is Control-C or Control-Break. But some emulators (such as DOSBox) do not process Control-C in a manner that will present it to the underlying program.
On some systems, you can press Ctrl-ScrollLock as a workaround:
I have a little trick for those interested: use Ctrl-ScrollLock, it behaves like Ctrl-Break with many BASIC interpreters running within DOSBox. It works with GW-BASIC, BASICA (often bundled with compatible DOSes like Compaq's), QBasic, QuickBasic, and possibly other development "workbench" interfaces.
The reason this works is a little complicated, so only read on if you're interested in knowing. DOSBox does not have true Ctrl-Break handling like real DOS, which is a combination of hardware and software interrupts and internal flags. However, the DOS Ctrl-Break handler is only a default handler that all starts with INT 9, the keyboard hardware interrupt. Many of the program development apps hook INT 9 and intercept keys before DOS sees them, so they can do their own processing. After all, the DOS default behavior for Ctrl-Break is to terminate the app, and that is often not what is wanted. The INT 9 handler code looks for the Control key being depressed by checking the shift status byte in BIOS data, and then reads scancodes from the keyboard data port 60h. The scancode for ScrollLock is 46h, and the scancode for Ctrl-Break is a 2-byte "escaped" sequence of E0h 46h, where E0h is the escape code. It seems the handler routines are often not very rigorous in their processing of the escape code, and just drop it, so Ctrl-ScrollLock ends up working the same as Ctrl-Break.
Kinda bad that you haven't had this answered...
Well to start, you will have to find the ASCII value of whatever key you would like to have be the exit.
To do this either make a simple program to figure it out using chr$,asc(),and an input. Or just search it real quick.
What you are going to want to do is in your games area where you are using an inkey$(Which I assume you are, because most games would have movement and that is almost required) and just check for the key being pressed along with every other key. For Example:
A simple movement game:
-Also, sorry if this is the incorrect method, but this should work...I'm still a bit rusty on GW