Re: [AD] nld_readkey()

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


> In my opinion, if the user presses a key on the keypad with num lock off
> (or on), then the program should only recognize the key the user wanted
> it to recognize, and not the key the user did NOT intend the program to
> recognize. (For example: if the user presses 'pgdn' on the keypad with
> num lock off, the program should recognize 'pgdn' and not 'keypad 3')
> Would anyone want to recognize a key the user did not intend?

Many games might need to distinguish between PGDN on main keyboard and
numpad.  Allegro must provide programmers with different scancodes for
both keys.  I agree that it would be nice to allow convertion of
numpad keys to their other meaning.  There are some problems though:

1) keyboard handler uses scancode to set flag in 'key' array, it uses
the same scancode to clear flag in 'key' array.  If you change
scancode for numpad keypress, but don't change it on keyrelease, flag
will stuck in 'key' array.  If you change scancodes for both keypress
and keyrelease, according to numlock state, then if user releases
numlock before releasing numpad key, it will stuck too.

2) only scancode is available with readkey for control keys.  You must
change scancode, if you want to convert numpad keys to some other
keys.

I think we should change keyboard handler a little to solve these
problems.  We can put original scancode into buffer and replacement
scancode together with ASCII value.  Or add one more field for
replacement scancode.  We'll need new function for getting original
scancode, or replacement scancode (depends on which scancode we should
return with readkey).

> By the way, I scrapped 'nld_readkey'. My most recent post presents a fix
> to pckeys.c that fixes up the _handle_pckey function (and "announces" my
> email address change). Apparently, there was a procedure in it that did
> change the scan code based on the state of num lock, but it didn't work
> due to some mistakes made. The patch I posted fixes it so it runs the way
> it was intended to, and some tiny modifications.

Does the following program work correctly with your modifications?

/* Exit with CTRL-ALT-END. */
#include <allegro.h>
int main (void)
{
  int pgup = 0;
  allegro_init ();
  set_gfx_mode (GFX_SAFE, 320, 200, 0, 0);
  install_keyboard ();
  while (1) {
    if (keypressed ())
      textprintf (screen, font, 0, 8, 15, "Pressed 0x%4.4X", readkey ());
    if (key[KEY_PGUP] && !pgup) {
      textout (screen, font, "Pressed PGUP ", 0, 0, 15);
      pgup = 1;
    }
    else if (!key[KEY_PGUP] && pgup) {
      textout (screen, font, "Released PGUP", 0, 0, 15);
      pgup = 0;
    }
  }
  return 0;
}
END_OF_MAIN ();

Try to press PGUP on main keyboard or keypad.  If you press it on
keypad and it says that PGUP is pressed, does it say it is released
when you release keypad PGUP?

-- 
Michael Bukin



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/