{{fbdoc item="title" value="SCREENEVENT"}}----
Queries for and retrieves system events.

{{fbdoc item="syntax"}}##
	[[KeyPgDeclare|declare]] [[KeyPgFunction|function]] **""ScreenEvent""** ( [[KeyPgByval|byval]] event [[KeyPgAs|as]] [[KeyPgAny|any]] [[KeyPgPtr|ptr]] = 0 ) [[KeyPgAs|as]] [[KeyPgLong|long]]
##
{{fbdoc item="usage"}}##
	//result// = **""ScreenEvent""**( [ //event// ] )
##
{{fbdoc item="param"}}
	##//event//##
		Specifies the buffer where the function should store the event data.

{{fbdoc item="ret"}}
	Returns ##-1## if there are pending events to be retrieved, ##0## otherwise.

{{fbdoc item="desc"}}
	This function returns the latest available system event from the internal ""GfxLib"" events queue. By "event" we mean any mouse or keyboard activity, for example.
	
	The event data (if available) will be copied into the buffer pointed that should be declared as an ##[[KeyPgEvent|Event]]##.
	On the ##[[KeyPgEvent|Event]]## page, see the list of event types and how to use their associated fields (see also the example below).
	
	__Querying for events__
		The function returns ##-1## if there are pending events to be retrieved, ##0## otherwise. If the ##//event//## parameter is set to ##0## (the default if omitted) ##[[KeyPgScreenevent|ScreenEvent]]## will not be able to copy the event data and it will not dequeue it from the internal events queue. Calling the function this way can be useful to check if there are pending events without actually fetching them.
		
	__Note__
		If you receive a KEY_PRESS, KEY_RELEASE or KEY_REPEAT event, it does not clear the keyboard buffer.  If you need the buffer to be clear after you receive the event, you will need to clear it manually.  See ##[[KeyPgInkey|Inkey]]##.
		
{{fbdoc item="ex"}}
{{fbdoc item="filename" value="examples/manual/gfx/screenevent.bas"}}%%(freebasic)
'' include fbgfx.bi for some useful definitions
#include "fbgfx.bi"
#if __FB_LANG__ = "fb"
using fb '' constants and structures are stored in the FB namespace in lang fb
#endif

dim e as EVENT

screenres 640, 480
do
	if (screenevent(@e)) then
		select case e.type
		case EVENT_KEY_PRESS
			if (e.scancode = SC_ESCAPE) then
				end
			end if
			if (e.ascii > 0) then
				print "'" & e.ascii & "'";
			else
				print "unknown key";
			end if
			print " was pressed (scancode " & e.scancode & ")"
		case EVENT_KEY_RELEASE
			if (e.ascii > 0) then
				print "'" & e.ascii & "'";
			else
				print "unknown key";
			end if
			print " was released (scancode " & e.scancode & ")"
		case EVENT_KEY_REPEAT
			if (e.ascii > 0) then
				print "'" & e.ascii & "'";
			else
				print "unknown key";
			end if
			print " is being repeated (scancode " & e.scancode & ")"
		case EVENT_MOUSE_MOVE
			print "mouse moved to " & e.x & "," & e.y & " (delta " & e.dx & "," & e.dy & ")"
		case EVENT_MOUSE_BUTTON_PRESS
			if (e.button = BUTTON_LEFT) then
				print "left";
			elseif (e.button = BUTTON_RIGHT) then
				print "right";
			else
				print "middle";
			end if
			print " button pressed"
		case EVENT_MOUSE_BUTTON_RELEASE
			if (e.button = BUTTON_LEFT) then
				print "left";
			elseif (e.button = BUTTON_RIGHT) then
				print "right";
			else
				print "middle";
			end if
			print " button released"
		Case EVENT_MOUSE_DOUBLE_CLICK
			If (e.button = BUTTON_LEFT) Then
				Print "left";
			Elseif (e.button = BUTTON_RIGHT) Then
				Print "right";
			Else
				Print "middle";
			End If
			Print " button double clicked"
		case EVENT_MOUSE_WHEEL
			print "mouse wheel moved to position " & e.z
		case EVENT_MOUSE_ENTER
			print "mouse moved into program window"
		case EVENT_MOUSE_EXIT
			print "mouse moved out of program window"
		case EVENT_WINDOW_GOT_FOCUS
			print "program window got focus"
		case EVENT_WINDOW_LOST_FOCUS
			print "program window lost focus"
		case EVENT_WINDOW_CLOSE
			end
		case EVENT_MOUSE_HWHEEL
			print "horizontal mouse wheel moved to position " & e.w
		end select
	end if

	sleep 1
loop
%%

{{fbdoc item="target"}}
	- ##**Screenevent**## does not return window related events in the DOS version, but does return input events.

{{fbdoc item="lang"}}
	- Not available in the //[[CompilerOptlang|-lang qb]]// dialect.

{{fbdoc item="diff"}}
	- New to ""FreeBASIC""

{{fbdoc item="see"}}
	- ##[[KeyPgEvent|Event]]##
	- ##[[KeyPgScreengraphics|Screen (Graphics)]]##
	- ##[[KeyPgInkey|Inkey]]##
	- ##[[KeyPgMultikey|Multikey]]##
	- ##[[KeyPgGetmouse|Getmouse]]##
	- [[ProPgEventHandling|Event Handling]]

{{fbdoc item="back" value="CatPgGfxScreen|Screen Functions"}}