Delphi Programming Skill Bit

Source: Internet
Author: User

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);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.