Code archives/User Input/Simple Pause Game
This code has been declared by its author to be Public Domain code.
Download source code
| Using the User32.dll library, GetKeyState(), the Pause/Break key acts like a switch. the switch can then be checked repetitiously in a loop for changes.|
The only complication, is that the Pause/Break key 'switch' may already be turned ON prior to running the program, or as a result of exiting a 'paused' game.
This entails an initial setting to reflect the state of the key, and store it as adefault non-paused value.
The code requires a .decls file with the following declaration:
.Lib "user32.dll" GetKeyState% (nVirtKey%) : "GetKeyState"
Place these lines into a text file, and save it as "user32.decls" in the userlibs folder.
;INITIALISATION Global b_gam_PAUSESTATE_PAUSED=(Not(GetKeyState(19))) ; FUNCTIONS Function b_cnt_Paused() ;Allows Pause/Break key to toggle Pause mode and returns True if Paused. ; Ensure v_cnt_InitialisePause() is called at program initialisation if you use this function! Return (GetKeyState(19)=b_gam_PAUSESTATE_PAUSED) ;$13 = VK_PAUSE End Function ; EXAMPLE: While Not KeyDown(1) Cls FlushKeys() If (b_cnt_Paused()) Text 0,0,("Game is paused") Else Text 0,0, ("Game is not paused") End If Flip Wend
Code Archives Forum