example:
a:=VkKeyScan('x');
More help in your win32.hlp file at your hard disk :)
Main Topics
Browse All TopicsHi, I am searching for a solution to convert a string to Virtkey like:
Var
a : TVirtkey;
begin
a := VKY;
AddHotKey(a, [hkCtrl,hkAlt]); // or - I know - simplier: AddHotKey(VKY, [hkCtrl,hkAlt]);
end;
Is there some stuff, to realize code like:
Var
a : String;
begin
a := 'VK'+'Edit1.Text';
AddHotKey(a, [hkCtrl,hkAlt]);
end;
perhaps a funktion like StrToVirt( ) ???
Thanks
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Virtual Key Codes are just constants
i.e. VK_DELETE = 46
these are listed in windows.pas
so you would need to copy these defs to a another unit that included those defs again and did the conversion
so something like this untested code
function GetHotKey(KeyStr: string): integer;
begin
if KeyStr='DELETE' then
Result:=VK_DELETE
else if KeyStr='INSERT' then
Result:=VK_INSERT
else if etc.etc.etc.
end;
I'm not sure where your string is coming from, but you may want to consider using the HotKeys from ComCtrls. This will give you a tShortCut valid for any shortcut you want. Using the HotKeys control gives you access to an always valid key combination (maybe except for the key 'none') so you don't have to worry about parsing a string that may or may not be valid. Once you have your tShortcut you can use any of these functions: (with Menus in your uses list). The examples below will be all using the shortcut Ctrl+S
function shortCutToText(shortcut: tShortCut) : string
myShortCutText := shortCutToText(myShortCut)
(creates the text "Ctrl+S" from the shortCut value (type word));
function shortCut(key: Word; shift: tShiftState): tShortCut; where key is a valid VK_KEY
myShortCut := shortCut(ord('s'), [ssCtrl])
(create a shortcut from a key (ord('s')) and shift [ssCtrl]
procedure shortCutToKey(shortCut: tShortCut; var key: Word; var shift: TShiftState);
key would become the VK of 's' and shift will contain [ssCtrl];
lastly there is:
function TextToShortCut(Text: string): TShortCut;
'Ctrl+S' returns the tShortCut word value; This function is slow, so I don't recommend using it.
If you are required to go from "Text" to "Virtual Keys", you could use TextToShortCut, then shortCutToKey.
Business Accounts
Answer for Membership
by: RadikalQ3Posted on 2005-07-20 at 10:27:15ID: 14487092
Use ;
VKCode:=VkKeyScan(Ch:char)