www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/30/06:36:27

From: Tom Burgess <Tom_Burgess AT bc DOT sympatico DOT ca>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Allegro Question
Date: Sun, 30 Mar 1997 01:29:08 -0700
Organization: BCTEL Advanced Communications
Lines: 18
Message-ID: <333E2454.6875@bc.sympatico.ca>
References: <19970329000031723 DOT AAA166 AT ns1 DOT megsinet DOT net>
NNTP-Posting-Host: pntn02m01-41.bctel.ca
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Paul Schmidt wrote:
> 
> How do you use the following?
> Do you bitwise AND 2 constants together to see if they are both pressed?
> Like if (KB_SHIFT_FLAG & KB_CTRL_FLAG)
> printf("Shift and CTRL Pressed\n");
> ?Close, but what you want is
	if ((KB_SHIFT_FLAG & key_shifts) && (KB_CTRL_FLAG & key_shifts))
		printf("Shift and CTRL Pressed\n");

where key_shifts contains a bunch of flags. Note that the bitwise & is
used to extract the flag, and the logical && is used to combine them
so that both must be non-zero for the test to pass. The extra parenthesis
will be appreciated by future maintainers of your code.

	regards, tom

	regards, tom.

- Raw text -


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