• 检测Insert、Capslock、NumLock、ScrollLock状态键的状态


    unit Unit1;

    interface

    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, AppEvnts, ComCtrls;

    type
      TForm1 = class(TForm)
        StatusBar1: TStatusBar;
        ApplicationEvents1: TApplicationEvents;
        procedure FormResize(Sender: TObject);
        procedure ApplicationEvents1Message(var Msg: tagMSG;
          var Handled: Boolean);
      private
        { Private declarations }
      public
        { Public declarations }
      end;

    var
      Form1: TForm1;

    implementation

    {$R *.dfm}

    procedure TForm1.FormResize(Sender: TObject);
    begin
        with StatusBar1 do
        begin
            Panels[0].Width:=Form1.Width - Panels[1].Width -Panels[2].Width-Panels[3].Width -50;
        end;
    end;

    procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
      var Handled: Boolean);
    begin
        if GetKeyState(VK_CAPITAL) <> 0 then
          StatusBar1.Panels[1].Text := ' CAP'
        else
          StatusBar1.Panels[1].text:='';

        if GetKeyState(VK_NUMLOCK) <> 0 then
          StatusBar1.Panels[2].Text := ' NUM'
        else
          StatusBar1.Panels[2].Text := '';

        if GetKeyState(VK_SCROLL) <> 0 then
          StatusBar1.Panels[3].Text := ' SCRL'
        else
          StatusBar1.Panels[3].Text := '';
    End;

    end.


    可以调用Win API的Getkeyboardstate()函数。
        常量        按键名称
    VK_INSERTI    nsert键
    VK_NUMLOCK    Num Lock键
    VK_CAPITAL    Caps Lock键
    VK_SCROLL     Scroll Lock键
      键盘缓冲区每一位都有一位特定的格式,对于状态键来说,最低位是1时表示状态键处于ON状态,你可以使用odd()函数来确定这一位的状态,以下是一个简单的例子请参考。例子中放置一个Timer控件、一个StayusBar1状态条。

    unit Unit1;
    interface
    uses
    Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
    ExtCtrls, ComCtrls;
    type
    TForm1 = class(TForm)
    StatusBar1: TStatusBar;
    Timer1: TTimer;
    procedure Timer1Timer(Sender: TObject);
    private
    { Private declarations }
    public
    { Public declarations }
    end;
    var
    Form1: TForm1;
    implementation
    {$R *.DFM}
    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.




    附件列表

    • 相关阅读:
      python简单应用!用爬虫来采集天猫所有优惠券信息,写入本地文件
      python有哪些好玩的应用实现,用python爬虫做一个二维码生成器
      Python学习,给自己的代码做个合集,定制自己的桌面软件!
      用python抓取“3d”彩票数据,怎么分析你说了算!
      怎么让你的代码更Pythonic?光有技巧可不行,你还需要看这些
      Python学习汇总,做数据采集的一些小技巧,干货满满
      Python学习,还在用正则或者bs4做爬虫吗?来试试css选择器吧
      C# Windows API判断当前窗口是否与其他窗口有重叠(USER32.dll、dwmapi.dll)
      asp.net mvc 设置文本框的宽高
      C++ 判断当前系统x64 or x86
    • 原文地址:https://www.cnblogs.com/xe2011/p/3876120.html
    Copyright © 2020-2023  润新知