1. How to detect the status of inserts, CapsLock, NumLock, ScrollLock state keys
Delphi can invoke the Getkeyboardstate () function of the win API.
Constant Key Name
Vk_insert Znsert Key
Vk_numlock NUM LOCK key
Vk_capital Caps Lock key
Vk_scroll SCROLL Lock key
Each bit of the keyboard buffer has a specific format, for the state key, the lowest bit is 1 when the state key is on state, you can use the odd () function to determine the status of this bit, the following is a simple example please refer to. The example places a Timer control, a StatusBar State bar.
procedure TForm1.Timer1Timer(Sender: TObject);
var ks:tkeyboardstate;
begin
getkeyboardstate(ks);//检测键盘函数
if odd(ks[VK_NUMLOCK]) then
statusbar1.panels.items[0].text:=NUM
else
statusbar1.panels.items[0].text:=;
if odd(ks[VK_INSERT]) then
statusbar1.panels.items[1].text:=INSERT
else
statusbar1.panels.items[1].text:=;
if odd(ks[VK_CAPITAL]) then
statusbar1.panels.items[2].text:=CAPITAL
else
statusbar1.panels.items[2].text:= ;
if odd(ks[VK_SCROLL]) then
statusbar1.panels.items[3].text:=SCROLL
else
statusbar1.panels.items[3].text:=;
end;
end.
2. Screen System Key
Maybe you want the program to not have the user press the System button Alt-tab or Ctrl-alt-del at run time, then you can use the following procedures to screen these keys.
procedure TForm1.FormCreate(Sender: TObject); var tmp,Flag :integer;
begin
tmp := 0;
Flag := 1;
//屏蔽 Alt-Tab
SystemParametersInfo( SPI_SETFASTTA-SKSWITCH, Flag, @tmp, 0);
//屏蔽 Ctrl-Alt-Del
SystemParametersInfo( SPI_SCREENSAVERRU-NNING,Flag, @tmp, 0);
end;
当你要恢复功能键时用以下代码:
Flag := 0;
SystemParametersInfo(SPI_SCREENSAVERRU-NNING,Flag,@temp,0);