delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/16/20:01:44

From: Jonathan Foster <jgf1 AT ukc DOT ac DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: problem with readkey()
Date: Thu, 16 Oct 1997 21:15:34 +0100
Organization: University of Kent at Canterbury, England
Message-ID: <344675E6.177A@ukc.ac.uk>
References: <01bcda6c$d9e94d80$0200a8c0 AT ingo>
NNTP-Posting-Host: dhcp2dd5.ukc.ac.uk
Mime-Version: 1.0
Lines: 38
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Ingo Ruhnke wrote:
> 
> I got here some simple code which dosen't run as I expect it to work:
>  if (readkey() == 'a') {
> 
> this didn't get me the info about that was pressed, it said every time 
> "a wasn't pressed", but if i modify it to this:
> 
>  char c;
>  if ((c = readkey()) == 'a') {
> the programm works fine. Can anybody tell me why this is so. And if
> i use getchar() instead of readkey() it also works like expected, 
> so were is the problem which this code.

I think allegro returns the scancode or similar data in the high byte
returned by readkey().

Assigning this to a "char" will lose the high byte, leaving the letter.

A more explicit way of coding this is:

  if ( (char)readkey() == 'a') {
OR
  if ( (readkey() & 0xFF) == 'a') {

Note the single "&" (bitwise and)

Hope this helps.

P.S. There is a mailing list for allegro - visit this site for how
to join:

http://www.talula.demon.co.uk/allegro/

-- 
   Jon Foster.

(1st Year Maths/Computer Science Student)

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019