Qbasicnews.com
Modified example from FB for keyboard input for SDL - Printable Version

+- Qbasicnews.com (http://qbasicnews.com/newforum)
+-- Forum: Qbasic "like" compilers/interpreters (http://qbasicnews.com/newforum/forum-5.html)
+--- Forum: FB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-15.html)
+--- Thread: Modified example from FB for keyboard input for SDL (/thread-6132.html)



Modified example from FB for keyboard input for SDL - BastetFurry - 02-19-2005

Himeowth!

I have modified the keymouse.bas programm so that it show a better way to retrive keyboard input for games. Have fun and dont give up coding Wink

Code:
''
'' SDL events test
'' by marzec
'' modified by BastetFurry for showing how to grab game input
''

'$include: 'SDL\SDL.bi'

declare sub DoKeyPrint ()
declare sub doInit ( )
declare sub doQuit ( )
declare sub doMain ( )
declare sub exitError ( msg as string )

dim video as SDL_Surface ptr
dim shared event as SDL_Event    
doInit
doMain
doQuit



sub doInit ( )

    if(SDL_Init( SDL_INIT_EVERYTHING )) then exitError "couldn't init SDL"
    
    video = SDL_SetVideoMode ( 320, 200, 24, SDL_HWSURFACE )
    if( video = 0 ) then exitError "couldn't init videomode"
    
end sub

sub doMain ( )
        
   dim keysdown as Integer
    dim quit as Integer
    quit = 1

    print "-----------------------------------------------"
    print "                  SDL TEST"
    print "-----------------------------------------------"

    while( quit = 1)

      if keysdown = 1 then DoKeyPrint
    
        while( SDL_PollEvent ( @event ) )                         
          print "event happened, type:" + str(event.type)        

            select case event.type
            case SDL_KEYDOWN:
               keysdown = 1
            case SDL_KEYUP:
               keysdown = 0
                case SDL_MOUSEBUTTONDOWN:
                    print "mousebutton pressed, quitting"
                    quit = 0
            end select
    
        wend
        
    wend
    
    print "leaving doMain"
end sub

sub DoKeyPrint ()
   SDL_PollEvent ( @event )
    print "key event, pressed key:" + str(event.key.keysym.sym) + " " + chr$(event.key.keysym.sym)
    print
end sub  

sub doQuit ( )

    print "quiting"
    SDL_Quit

end sub

sub exitError ( msg as string )
    print "error: " + msg
    SDL_Quit
    end
end sub

(How to tag this as qbasic code? I have seen it somewhere but dont know how)

So Long, The Werelion!


Modified example from FB for keyboard input for SDL - dutchtux - 02-20-2005

Well I got it more this way:

Code:
dim shared keyboardkey(0 to 323) as integer

if keyboardkey(SDLK_F2) <> 0 then dostuff

'' Get Keyboard State
sub getkeyboardstate()
   dim e%
   dim keyboarddata as ubyte ptr
   keyboarddata = SDL_GetKeyState(0)
   for e% = 1 to 323
      keyboardkey(e%) = PEEK(keyboarddata + e%)
   next  
end sub

It's I think beter because it looks at all keys and make them 1 if they are pressed.


Modified example from FB for keyboard input for SDL - Z!re - 02-20-2005

Code:
Dim key as ubyte ptr
Do
       key = SDL_GetKeystate(0)
Loop Until Peek(key + SDLK_ESCAPE)
Can be simplified to:
Code:
Dim key as ubyte ptr
Do
       key = SDL_GetKeystate(0)
Loop Until key[SDLK_ESCAPE]
Fancy, ey?