6
6941941
Unregistered / Unconfirmed
GUEST, unregistred user!
你们遇到过这样的情况吗?
用低级键盘钩子WH_KEYBOARD_LL 记录键盘,在本程序里面输入,能识别出大小写,但是在别的程序里面输入不能识别,一开始是什么状态,就一直是什么状态.
下面的代码是处理返回键值的函数。
function GetTrueKey(wpa: integer): char;
const
dd1:array[0..11]of byte=($20,$C0,$BD,$BB,$DC,$DB,$DD,$BA,$DE,$BC,$BE,$BF);
dd2:array[0..11]of char=(' ','`','-', '=', '/', '[', ']', ';', '''', ',', '.', '/');
key1: array[0..20] of char = ('`', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '/', '[', ']', ';', '''', ',', '.', '/');
key2: array[0..20] of char = ('~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '|', '{', '}', ':', '"', '<', '>', '?');
var
KeyboardState: TKeyboardState;
i: integer;
found:boolean;
begin
GetKeyboardState(KeyboardState);
if (KeyboardState[VK_CONTROL] and $80 <> 0) or (KeyboardState[VK_MENU] and $80 <> 0) then
begin
result:=#0;
exit;
end;
result := chr(WPa);
if (result >= 'A') and (result <= 'Z') then
begin
if KeyboardState[VK_CAPITAL] and $1 <> 0 then result := chr(WPa)
else result := chr(WPa + $20);
if KeyboardState[VK_SHIFT] and $80 <> 0 then
begin
if result <= 'Z' then inc(result, $20)
else dec(result, $20);
end;
end
else if(wpa>=VK_NUMPAD0)and(wpa<=VK_DIVIDE)then
begin
if wpa<=VK_NUMPAD9 then result:=chr($30+wpa-VK_NUMPAD0)
else if wpa=VK_MULTIPLY then result:='*'
else if wpa=VK_ADD then result:='+'
else if wpa=VK_DIVIDE then result:='/'
else if wpa=VK_SUBTRACT then result:='-'
else if wpa=VK_DECIMAL then result:='.';
exit;
end
else if (result>='0')and(result<='9') then //nothing
else begin
found:=false;
for i := low(dd1) to high(dd1) do
begin
if wpa = dd1 then
begin
result := dd2;
found:=true;
end;
end;
if not found then
begin
result:=#0;
exit;
end;
end;
if KeyboardState[VK_SHIFT] and $80 <> 0 then
for i := low(key1) to high(key1) do
begin
if result = key1 then
begin
result := key2;
end;
end;
end;
用低级键盘钩子WH_KEYBOARD_LL 记录键盘,在本程序里面输入,能识别出大小写,但是在别的程序里面输入不能识别,一开始是什么状态,就一直是什么状态.
下面的代码是处理返回键值的函数。
function GetTrueKey(wpa: integer): char;
const
dd1:array[0..11]of byte=($20,$C0,$BD,$BB,$DC,$DB,$DD,$BA,$DE,$BC,$BE,$BF);
dd2:array[0..11]of char=(' ','`','-', '=', '/', '[', ']', ';', '''', ',', '.', '/');
key1: array[0..20] of char = ('`', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '/', '[', ']', ';', '''', ',', '.', '/');
key2: array[0..20] of char = ('~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '|', '{', '}', ':', '"', '<', '>', '?');
var
KeyboardState: TKeyboardState;
i: integer;
found:boolean;
begin
GetKeyboardState(KeyboardState);
if (KeyboardState[VK_CONTROL] and $80 <> 0) or (KeyboardState[VK_MENU] and $80 <> 0) then
begin
result:=#0;
exit;
end;
result := chr(WPa);
if (result >= 'A') and (result <= 'Z') then
begin
if KeyboardState[VK_CAPITAL] and $1 <> 0 then result := chr(WPa)
else result := chr(WPa + $20);
if KeyboardState[VK_SHIFT] and $80 <> 0 then
begin
if result <= 'Z' then inc(result, $20)
else dec(result, $20);
end;
end
else if(wpa>=VK_NUMPAD0)and(wpa<=VK_DIVIDE)then
begin
if wpa<=VK_NUMPAD9 then result:=chr($30+wpa-VK_NUMPAD0)
else if wpa=VK_MULTIPLY then result:='*'
else if wpa=VK_ADD then result:='+'
else if wpa=VK_DIVIDE then result:='/'
else if wpa=VK_SUBTRACT then result:='-'
else if wpa=VK_DECIMAL then result:='.';
exit;
end
else if (result>='0')and(result<='9') then //nothing
else begin
found:=false;
for i := low(dd1) to high(dd1) do
begin
if wpa = dd1 then
begin
result := dd2;
found:=true;
end;
end;
if not found then
begin
result:=#0;
exit;
end;
end;
if KeyboardState[VK_SHIFT] and $80 <> 0 then
for i := low(key1) to high(key1) do
begin
if result = key1 then
begin
result := key2;
end;
end;
end;