Mail Archives: djgpp/1997/03/30/06:36:27
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 -