[A89] Re: OSDequeue


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

[A89] Re: OSDequeue




John David Ratliff wrote:

> -------------------
> >
> > How do you implement this and save the key press to a variable,
> every
> > time I do it the thing won't work!
> >
> >
> >
> >
>
> OSdequeue for keyboard reading is very simple.
>
> #include <system.h>
> #include <kbd.h>
>
> short int getKey(short int wait) {
>     unsigned short int key = 0;
>     short int done = 0;
>     void *kbq = kbd_queue();
>
>     while (!done) {
>         if (!wait || !OSdequeue(&key,kbq)) {
>             done = 1;
>         }
>     }
>
>     return (signed short int)key;
> }
>
> It's sometimes a good idea to cast it to a signed int to avoid
> warnings between signed and unsigned comparisons, which you will often
> get when comparing the KEY macros, like arrow keys KEY_LEFT.
>
> So, if you want to use that function...
>
> void _main(void) {
>     short int key;
>
>     key = getKey(1);
> }
>
> This will wait until a key is available and return the signed
> keypress, stored in the variable key local to the _main() function.
>
> OSdequeue() will not work if you have disabled interrupts or
> redirected auto-int 1. If you did this, you will have to use low-level
> keyboard reading...
>
> Hope this helps...
>
> John David Ratliff
> jdratlif@cs.indiana.edu

When the compiler goes over void kbq = kdb_queue(); it gives an error




Follow-Ups: References: