TGC Codebase Backup



Anykey detection (quick and easy) by Steve Ancell

12th Mar 2023 13:19
Summary

A couple of functions that will come in handy when needing to wait for any key to be pressed or released. A typical usage would be when transitioning the end of levels, game over a



Description



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    [code lang=agk]
function AnyKeyPressed()
	local flag as integer
	
	if GetRawKeyPressed(GetRawLastKey())
		flag = 1
		
	else
		flag = 0
		
	endif
	
endfunction flag

function AnyKeyReleased()
	local flag as integer
	
	if GetRawKeyReleased(GetRawLastKey())
		flag = 1
		
	else
		flag = 0
		
	endif
	
endfunction flag

while AnyKeyPressed() = 0
	sync()
	
endwhile

do
	if AnyKeyReleased() = 1
		exit
		
	endif
	
	sync()
	
loop
[/code]