Quote
Cameron McCormack wrote:
> 'Cause you're getting two of every character, it looks like you're getting
> the WM_CHAR messages which have the 31st bit of the lParam value is set.
> This bit is 1 if the key is released, and 0 if the key is pressed.
Oddly enough, no! Having checked my bits fairly carefully, this isn't
the cause.. Take a look at WM_DEADCHAR!
Quote
> Look up WM_CHAR in the Win32 SDK.
Did that a long time ago....
Quote
> Since it is the TranslateMessage function which posts the WM_CHAR messages,
> I'm not sure how the particular application would handle this. One reason
> could be that when they handle the WM_KEYDOWN message they don't translate
> it if it is a key release.
This is what I suspect... the app is possibly posting or translating the
char twice... Just out of interest, I can't really ignore WM_CHAR
messages when the key is being released, just in case they key is being
held down. My current code looks like this:
type
TCharRec=packed record
CharCode:WPARAM;
KeyData:LPARAM;
end;
procedure WriteCharRec(var CharRec:TCharRec;Stream:TBlockMemoryStream);
var
Character:char;
RepCount,iterate:word;
begin
{Ignore characters with bit 31 or 30 set in the lparam}
if {((CharRec.KeyData and $C0000000)=0)}true then
begin
Character:=Char((CharRec.CharCode and $00FF)); //Bottom 8 bits only
{Now need to see how many times the thing has been repeated
as a result of it being held down}
RepCount:=CharRec.KeyData and $0000FFFF;
for iterate:=0 to RepCount-1 do
begin
case Character of
{CR}#13:begin
Character:=#13;
Stream.WriteBuffer(Character,SizeOf(Character));
Character:=#10;
Stream.WriteBuffer(Character,SizeOf(Character));
end;
{DEL}#127:WriteString('<DEL>',Stream);
#0..#12,#14..#31:WriteASCIICode(Character,Stream);
else
Stream.WriteBuffer(Character,SizeOf(Character));
end;
end;
end;
end;
procedure WriteASCIICode(Character:char;Stream:TBlockMemoryStream);
type
StringArray=array[#0..#31] of string;
const
ASCIICodes:StringArray =
('<NUL>','<SOH>','<STX>','<ETX>','<EOT>','<ENQ>','<ACK>','<BEL>',
'<BS>','<HT>','<LF>','<VT>','<FF>','<CR>','<SO>','<SI>',
'<DLE>','<DC1>','<DC2>','<DC3>','<DC4>','<NAK>','<SYN>','<ETB>',
'<CAN>','<EM>','<SUB>','<ESC>','<FS>','<GS>','<RS>','<US>');
begin
WriteString(ASCIICodes[Character],Stream);
end;
--
Martin Harvey.
http://www.harvey27.demon.co.uk/mch24/
PGP key available from above address,
or http://wwwkeys.pgp.net/