Asynchronous keyboard callbacks (was: [AD] Proposal for an input model) |
[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]
I wrote: >> So how about we provide blocking versions of the keypress functions? In reply to Eric Botcazou <ebotcazou@xxxxxxxxxx>: >This would mean that we effectively drop the DOS support: asynchronous input >requires callbacks under DOS. Well then, how about: al_get_bool("/keyboard/caps/asynch"); which would return true on platforms where asynchronous input is truly available (DOS), and false on platforms where it is emulated (Linux). A potential program could decide to use its own thread in preference to having emulated callbacks -- you might want to do this because of the extra flexibility. To register callbacks, you would call: al_register_keyboard_callback(void(*)(int)); al_register_scancode_callback(void (*)(int)); where the function takes parameters in the format described by al_read_key() and al_read_scancode(), respectively. On DOS, this would be trivial. On Linux, this would be fairly difficult; the very simple polling system would need to be unhooked, and a different subsystem (operating in its own thread) would be installed and have to emulate the current system. (This is why I didn't want to have callbacks). Presumably executing read() on the keyboard's file descriptor will block until there is some input available? I don't know the details for other platforms. >> This way, coders will need to create their own thread, but once that is >> done, everything is nice and simple. > >I only hope every user knows what is behind the 'once that is done', and >especially how to do it in a portable way... Hmm. It would be simpler, solving both your questions, if we provide our own thread API, but should we really do that? It would add some complexity to the code, and perhaps defeat the point of other thread packages (like pthreads) which are ported to many systems, but I personally would like it because it insulates me from OS dependent stuff. Bye for now, -- Laurence Withers, lwithers@xxxxxxxxxx http://www.lwithers.demon.co.uk/
Attachment:
signature.asc
Description: PGP signature
Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |