|
|
发表于 2006-1-4 13:31:00
|
显示全部楼层
Re:?教一下: 如何??y??被按下
GetKeyBoardState,没用过??
身为MS平台下的程序员,居然不好好看MSDN,或者win32API帮助,就不要编程了!
procedure KeyBoardStateToGUI(var key: TGUIKeyBoard);
var
i: Integer;
keys: TKeyboardState;
function keytoggled(vk: integer): boolean;
begin
Result := (keys[vk] and 1) <> 0;
end;
function keypressed(vk: integer): boolean;
begin
Result := (keys[vk] and $80) <> 0;
end;
function VKToShifts: TGUIShifts;
begin
Result := [];
if keypressed(VK_SHIFT) or keypressed(VK_LSHIFT) or keypressed(VK_RSHIFT)
then
Include(Result, ssShift);
if keypressed(VK_CONTROL) or keypressed(VK_LCONTROL) or
keypressed(VK_RCONTROL) then
Include(Result, ssCtrl);
if keypressed(VK_MENU) or keypressed(VK_LMENU) or keypressed(VK_RMENU) then
Include(Result, ssAlt);
end;
function VKToGUIKey(VKey: WORD): TGUIKey;
var
caps: boolean;
const
chars1: array['0'..'9'] of char = ')!@#$%^&*(';
chars2s: array[$BA..$C0] of char = ';=,-./`';
chars2b: array[$BA..$C0] of char = ':+<_>?~';
chars3s: array[$DB..$DE] of char = '[\]''';
chars3b: array[$DB..$DE] of char = '{|}"';
begin
//remap (caps) A,a..z,Z
//remap other chars
//remap special keys ? BS,DEL,ENTER,ESC,LEFT,RIGHT,UP,DOWN
caps := ssShift in key.shifts;
if keytoggled(VK_CAPITAL) then
caps := not caps;
case chr(Vkey) of
'A'..'Z':
begin
Result := VKey;
if not caps then
Result := Result - ord('A') + ord('a');
end;
' ':
Result := Vkey;
'0'..'9':
begin
Result := VKey;
if ssShift in key.shifts then
Result := WORD(chars1[chr(Result)]);
end;
chr(low(chars2s))..chr(high(chars2s)):
begin
Result := WORD(chars2s[vkey]);
if ssShift in key.shifts then
Result := WORD(chars2b[vkey]);
end;
chr(low(chars3s))..chr(high(chars3s)):
begin
Result := WORD(chars3s[vkey]);
if ssShift in key.shifts then
Result := WORD(chars3b[vkey]);
end;
else
begin
Result := VKey or $8000;
end;
end;
AddKeyToList(key, Result);
end;
begin
GetKeyBoardState(keys);
key.shifts := VKToShifts;
for i := low(keys) to high(keys) do
begin
if keys <> lastkeys then
if (keys and $80) <> 0 then
VKToGUIKey(i);
end;
lastkeys := keys;
end;
请理解我的激动........
|
|