如果使用者打到一半想輸入小寫的時候再自己按掉切換
當然,稍微修改一下,可以用來判斷大寫鍵(CapsLock)是否作用中
//宣告自定類別
type
TKeyType = (ktCapsLock, ktNumLock, ktScrollLock);
//設定是否Led作用
procedure TForm1.SetLedState(KeyCode: TKeyType; bOn: Boolean);
var
KBState: TKeyboardState;
Code: Byte;
begin
case KeyCode of
ktScrollLock: Code := VK_SCROLL;
ktCapsLock: Code := VK_CAPITAL;
ktNumLock: Code := VK_NUMLOCK;
end;
GetKeyboardState(KBState);
if (Win32Platform = VER_PLATFORM_WIN32_NT) then
begin
if Boolean(KBState[Code]) <> bOn then
begin
keybd_event(Code,
MapVirtualKey(Code, 0),
KEYEVENTF_EXTENDEDKEY,
0);
keybd_event(Code,
MapVirtualKey(Code, 0),
KEYEVENTF_EXTENDEDKEY or KEYEVENTF_KEYUP,
0);
end;
end
else
begin
KBState[Code] := Ord(bOn);
SetKeyboardState(KBState);
end;
end;
// Led全部打開
procedure TForm1.Button1Click(Sender: TObject);
begin
SetLedState(ktCapsLock, True); // CapsLock on
SetLedState(ktNumLock, True); // NumLock on
SetLedState(ktScrollLock, True); // ScrollLock on
end;
// Led全部關掉
procedure TForm1.Button2Click(Sender: TObject);
begin
SetLedState(ktCapsLock, false); // CapsLock off
SetLedState(ktNumLock, false); // NumLock off
SetLedState(ktScrollLock, false); // ScrollLock off
end;
//判斷大寫鍵狀態
if Odd(GetKeyState(vk_Capital)) then
begin
edtPassword.Hint:='大寫鍵(CapsLock)狀態:ON';
end
else
begin
edtPassword.Hint:='大寫鍵(CapsLock)狀態:OFF';
end;
沒有留言:
張貼留言