Richard -

I don't know where you got the impression that a 32 bit number is a 2 digit number, but it's not accurate. It can be represented by 4 hex values as in $FFFF, a decimal number from 0-2^32 (roughly 4 billion), or 32 0/1's in binary form. You can inspect the value of various bits using a bit-wise AND comparator (as in "if ($FFFF AND $0001)<>0 then dosomething;" where $FFFF is a 32-bit number with all 1's and $0001 is the first bit (leading 0's optional.) Most of the time I use a little shifter routine to make bitwise inspections easier.

function bitval(bit:byte):longint;
begin
if (bit>32) or (bit<1) then raise Exception.Create('Valid range for bitval is 1-32');
dec(bit);
result:=$1 shl bit;
end;

then I can write "if (someval AND bitval(4))<>0 then dosomething;" If you want to check multiple bits at the same time, or the bitval's together as such: "if (someval AND (bitval(4) or bitval(8)))<>0 then dosomething;"

if you want to build some static constants, it's very straight forward in hex:

const
bit1=$1;
bit2=$2;
bit3=$4;
bit4=$8;
bit5=$10;
bit6=$20;
bit7=$40;
bit8=$80;
etc. (just keep adding 0's to the end)

At any rate, regardless of all the bit wise operators in the preceeding, I think you really just need to us MapVirtualKey to convert the scan code back into a useable value. Otherwise you are going to be making a lot of assumptions about bits 16-23 being some fixed value and it's really not true. When you get into international keyboards, those scan codes could have different meanings than a traditional English keyboard.

Anyway, hope it helps. If you really want to manually break out the bits 16-23 or some such, let me know and I'll send you a routine to do it.

Marshall




Date: Thu, 27 Oct 2005 02:30:51 -0700
From: "Richard R" <[EMAIL PROTECTED]>
Subject: Re: lParam in message handler

Hello, I dont know how to extract data from a LParam value from a WM_KEYDOWN
message. Documentation says that LPARAM "Specifies the repeat count, scan
code, extended-key flag, context code, previous key-state flag, and
transition-state flag" well all I get is one big number. Since this
statement used "and" instead of "or" this makes me wonder if there is some
type of byte calculations that need to be done to extract each piece? Here
are the values

0-15 Specifies the repeat count. The value is the number of times the
keystroke is repeated as a result of the user holding down the key.
16-23 Specifies the scan code. The value depends on the original equipment
manufacturer (OEM).
24 Specifies whether the key is an extended key, such as the right-hand ALT
and CTRL keys that appear on an enhanced 101- or 102-key keyboard. The value
is 1 if it is an extended key; otherwise, it is 0.
25-28 Reserved; do not use.
29 Specifies the context code. The value is always 0 for a WM_KEYDOWN
message.
30 Specifies the previous key state. The value is 1 if the key is down
before the message is sent, or it is 0 if the key is up.
31 Specifies the transition state. The value is always 0 for a WM_KEYDOWN
message.

The lparam value I get in my function that hooks key strokes returns 983041.
Is this bogus data or should it have returned a 2 digit number as above?


------------------------------

_______________________________________________
Delphi-Talk mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi-talk


End of Delphi-Talk Digest, Vol 33, Issue 31
*******************************************



__________________________________________________
Delphi-Talk mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi-talk

Reply via email to