paragui-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to supply own events (was Re: [paragui-users] Several questions conc


From: Ulf Lorenz
Subject: How to supply own events (was Re: [paragui-users] Several questions concerning paraGUI)
Date: Sun, 25 Dec 2005 23:04:35 +0100
User-agent: Mutt/1.5.11

Another thing,

I have just looked at my code again and found that I may have had some
sort of lock in my brain. I am not sure what exactly you wanted to do,
but the example I sent you showed how to manipulate events (i.e.
translate/drop etc. some events). 

However, you may have been interested in creating events from arbitrary
sources. The function to use here is SDL_PushEvent (defined in
SDL_events.h). I.e. you basically assemble the event you want to have
and then add it to the (SDL-internal) event list. A small code example:


// Returns the key, whose pressing we want to emulate, has to be filled
// with the actual code to observe some device or whatever; it
// returns SDLK_UNKNOWN on error or when there was nothing
// pushed/switched/...
SDL_Key whichKey();


void addEvent()
{
    // look if we have to do any event at all
    SDL_Key key = whichKey();

    if (key == SDLK_UNKNOWN)
        return;

    // assemble a key down event at the location ev points to
    SDL_Event* ev = new SDL_Event;
    ev->type = SDL_KEYDOWN;
    ev->key.which = 0;              // keyboard device, paragui ignores this
    ev->key.state = SDL_PRESSED;    // the same, but for completeness...
    ev->key.keysym = key;

    SDL_PushEvent(ev);

    // assemble a key up event as well
    ev = new SDL_Event;
    ev->type = SDL_KEYUP;
    ev->key.which = 0;              // keyboard device, paragui ignores this
    ev->key.state = SDL_RELEASED;    // the same, but for completeness...
    ev->key.keysym = key;

    SDL_PushEvent(ev);
}



Building events like this is a bit cumbersome, but the SDL header files
are excellently documented. In this example, addEvent has to be called
somewhat regularily, either through a customized PG_EventSupplier (that
calls addEvent regularily; the difference to my other example would not
be too big, using SDL_PushEvent is only somewhat cleaner) or e.g. by a
timer.


Any questions left?


Ulf

-- 
recursive:
            see recursive




reply via email to

[Prev in Thread] Current Thread [Next in Thread]