bernani
asked on
Assigning a unicode char to a keyboard's key
Hello,
I'm using the following code to insert in a Memo all the values for a Greek font (SGreek) - only a draft to find all the possible combinations of voyels and accents for polytonic Greek (ancient Greek with diacritics, accents, ...) - in the form :
letter alpha[value]tab
where :
letter alpha : ascii 97
value : ascii value from 33 to 255 [= Ascii charset]
tab : ascii 9
for example:
//#97#175; gives á
//#97#220; gives à
// and so on ...
{test procedure for alpha - French keyboard}
var
i,
tempchar : integer;
begin
Memo1.Lines.Add('A'); //Title (letter alpha with the SGreek font
Memo1.Lines.Add(''); // blank line
for i:=33 to 255 do // for each 33 to 255 insert alpha+[value from 33 to 255]+tab
begin
tempchar:= i;//97+I; // ascii 97 = a for a French keyboard - q for US keyboard
Memo1.SelText:= #97 ; //initial value for Greek's alpha
SendMessage(Memo1.Handle,W M_CHAR,tem pchar,0); // insert letter alpha in Memo
Memo1.SelText:= '['+IntToStr(tempchar)+']' ; // insert accent (polytonic Greek)
SendMessage(Memo1.Handle,W M_CHAR,9,0 ); //insert tab (use tab column instead of space)
end;
// ...
end;
I'm also using the following code, in the Memo1KeyPress, to assign the needed combinations to one keybord's key:
if key = chr(65) {A}) then Memo1.SelText:= #97#175; to assign the Greek [alpha + acute accent] to the keyboard's key "A".
I need to do the same with the unicode equivalents codes.
If I use a complete Unicode font (Arial Unicode MS) and try the following code with the unicode-aware tntComponent:
procedure TForm1.TntMemo1KeyPress(Se nder: TObject; var Key: Char);
begin
if key = chr(65) {A} then tntMemo1.SelText:= #8049; //8049 is equivalent of #97#175 or [alpha + acute accent]
end;
the result will be: acute apha following by uppercase A.
How can I get rid of the uppercase A ? Or how can I assign a unicode char (widechar) to a keyboard's key. My aim is to map completely the keyboard with the new unicode values.
All ideas are welcome.
Thanks for your help,
I'm using the following code to insert in a Memo all the values for a Greek font (SGreek) - only a draft to find all the possible combinations of voyels and accents for polytonic Greek (ancient Greek with diacritics, accents, ...) - in the form :
letter alpha[value]tab
where :
letter alpha : ascii 97
value : ascii value from 33 to 255 [= Ascii charset]
tab : ascii 9
for example:
//#97#175; gives á
//#97#220; gives à
// and so on ...
{test procedure for alpha - French keyboard}
var
i,
tempchar : integer;
begin
Memo1.Lines.Add('A'); //Title (letter alpha with the SGreek font
Memo1.Lines.Add(''); // blank line
for i:=33 to 255 do // for each 33 to 255 insert alpha+[value from 33 to 255]+tab
begin
tempchar:= i;//97+I; // ascii 97 = a for a French keyboard - q for US keyboard
Memo1.SelText:= #97 ; //initial value for Greek's alpha
SendMessage(Memo1.Handle,W
Memo1.SelText:= '['+IntToStr(tempchar)+']'
SendMessage(Memo1.Handle,W
end;
// ...
end;
I'm also using the following code, in the Memo1KeyPress, to assign the needed combinations to one keybord's key:
if key = chr(65) {A}) then Memo1.SelText:= #97#175; to assign the Greek [alpha + acute accent] to the keyboard's key "A".
I need to do the same with the unicode equivalents codes.
If I use a complete Unicode font (Arial Unicode MS) and try the following code with the unicode-aware tntComponent:
procedure TForm1.TntMemo1KeyPress(Se
begin
if key = chr(65) {A} then tntMemo1.SelText:= #8049; //8049 is equivalent of #97#175 or [alpha + acute accent]
end;
the result will be: acute apha following by uppercase A.
How can I get rid of the uppercase A ? Or how can I assign a unicode char (widechar) to a keyboard's key. My aim is to map completely the keyboard with the new unicode values.
All ideas are welcome.
Thanks for your help,
ASKER
Thanks for your reply.
I've already tried all the possible combinations, in the three events (onKeyUp, onKeyPressed and onKeyDown) except that I didn't think to set ke key value to #0.
I've tried it , unfortunately It doesn't work. I still have my unicode char plus the char of the pressed key.
Using Ascii set, I can use this function to change the value of the key, in the onKeyPressed event:
key := #a value up to 255; //key is of type char and it's working OK
Using unicode, I can't do this assignment key:= #8049 due the fact that the assigned value is of type WideChar.
Doing that would generate a type mismatch. (Char and WideChar). It's the same problem with the sendmessage function SendMessage(Memo1.Handle,W M_CHAR,{a value between 0 and 255},0);
Maybe it would be necessary typecasting the WideChar to Char.
If I look the Api help, I find the following function:
VOID keybd_event(
BYTE bVk, // virtual-key code
BYTE bScan, // hardware scan code
DWORD dwFlags, // flags specifying various function options
DWORD dwExtraInfo // additional data associated with keystroke
);
Parameters
bVk: Specifies a virtual-key code. The code must be a value in the range 1 to 254.
bScan : Specifies a hardware scan code for the key.
dwFlags : A set of flag bits that specify various aspects of function operation. An application can use any combination of the following predefined constant values to set the flags:
Value Meaning
KEYEVENTF_EXTENDEDKEY If specified, the scan code was preceded by a prefix byte having the value 0xE0 (224).
KEYEVENTF_KEYUP If specified, the key is being released. If not specified, the key is being depressed.
dwExtraInfo : Specifies an additional 32-bit value associated with the key stroke.
But I don't know how I can implement that in Delphi ?
Have you got and idea ?
Thanks for your help,
I've already tried all the possible combinations, in the three events (onKeyUp, onKeyPressed and onKeyDown) except that I didn't think to set ke key value to #0.
I've tried it , unfortunately It doesn't work. I still have my unicode char plus the char of the pressed key.
Using Ascii set, I can use this function to change the value of the key, in the onKeyPressed event:
key := #a value up to 255; //key is of type char and it's working OK
Using unicode, I can't do this assignment key:= #8049 due the fact that the assigned value is of type WideChar.
Doing that would generate a type mismatch. (Char and WideChar). It's the same problem with the sendmessage function SendMessage(Memo1.Handle,W
Maybe it would be necessary typecasting the WideChar to Char.
If I look the Api help, I find the following function:
VOID keybd_event(
BYTE bVk, // virtual-key code
BYTE bScan, // hardware scan code
DWORD dwFlags, // flags specifying various function options
DWORD dwExtraInfo // additional data associated with keystroke
);
Parameters
bVk: Specifies a virtual-key code. The code must be a value in the range 1 to 254.
bScan : Specifies a hardware scan code for the key.
dwFlags : A set of flag bits that specify various aspects of function operation. An application can use any combination of the following predefined constant values to set the flags:
Value Meaning
KEYEVENTF_EXTENDEDKEY If specified, the scan code was preceded by a prefix byte having the value 0xE0 (224).
KEYEVENTF_KEYUP If specified, the key is being released. If not specified, the key is being depressed.
dwExtraInfo : Specifies an additional 32-bit value associated with the key stroke.
But I don't know how I can implement that in Delphi ?
Have you got and idea ?
Thanks for your help,
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
but after you insert your unicode-char set the keyValue to #0,
maybe use the onKeydown/onKeyUp instead of onKeyPressed
meikl ;-)