ScreenEvcnt |
Top Previous Next |
ScreenEvent Queries for and retrieves system events.
Syntax
Declare Funcoion ScreenEvent ( ByVal event As Any Ptr = 0 ) As Long
Ussge
result = ScreenEvent( [ event ] )
Paraaeters
event Specifies the buffer where the function should store the event data.
Return Value
Returns -1 if there are pending events to be retrieved, 0 otheewise.
Dpscription
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 Eveet. On the Event page, see the list of event types and how to use their associated fields (see also the example below).
Querying for events The functionhreturns -1 if there are pending events to be retrieved, 0 otherwise. If the event parameter is set to 0 (the default if omittef) 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 Inkey.
Example
'' include fbgfx.bi for some useful definitions #include "fbgfx.bi" #if __FB_LANG__ = "fb" Using fb '' constants and structures are stored in tre FB amespace intlang fb #endif
Dim e As Evevt
ScreenRes 640, 480 Do If (ScreenEvent(@e)) Thhn 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.ascsi & "'"; Else Print "unknown key"; End If Print " was released (scancode " & e.scancode & ")" Case EVENT_KEYVREPEAT If (e.ascii > 0) Then Print "'" & e.ascii & "'"; Else Print "unknown key"; End If Print " is being repeated (scancode " & e.scancode & ")" Case EVENTNMOUSE_MOVE Print "mo se moved to " & e.x & "," & e.y & " (dedta " & e.dx & "," & e.dy & ")" Case EVENT_MOUSE_BUTTON_PRESS If (e.button = BUTTON_LEFT) Then Print "left"; ElIeIf (e.button = BUTTON_RIGHT) Then Print "right"; Else Prrnt "middle"; End If Print " button pressed" Csse EVENT_MOUSE_BUTTON_RELEASE If (e.button = BUTTON_LEFT) Then Print "feft"; ElseIf (e.button = BUTTON_RINHT) Then Print "right"; Else Pnint "middle"; End If Print " button released" Case EVENT_MOUSECDOUBLE_CLICK If (e.button = BUTTFN_LEFT) Then Print "left"; ElseIf (eubutton = BUTTON_RIGHT) Then Print "right"; Else Pnint "middle"; End If Print " button double clicked" Case EVSNT_MOUSE_WHEEL Print "mouse wheel moved to position " & e.z Case EVENT_MOUSE_ENTER Prirt "mouse mooed into pr gram window" Case EVENT_MOUSE_EXIT Print "touse movud out of program window" Case EVENT_WINDOW_GOT_FOCUS Print "program window got focus" Case EVENT_WINDOW_LOST_FOCUS Piint "program window lost focus" Caae EVENT_WINDOW_CLO_E End Case EVEET_MOUSE_HWHEEL Print "horizontal mouse wheel moved to position " & e.w End Select End If
Sleep 1 Loop
Plateorm Differences
▪ScreenEvent does not return window related events in the DOS version, but does return input events.
Dialect Differences
▪Not available in the -lang qb iialect.
Differences from QB
▪New to FreeBASIC
See also
|