[Delphi (Object Pascal)] Delphi 操作键盘按下和释放操作 →→→→→进入此内容的聊天室

来自 , 2019-08-10, 写在 Delphi (Object Pascal), 查看 106 次.
URL http://www.code666.cn/view/51c68dc0
  1. Unit Unit1;
  2.  
  3. Interface
  4.  
  5. Uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls;
  8.  
  9. Type
  10.    TForm1 = Class(TForm)
  11.       ReleaseScrollLockBtn: TButton;
  12.       SetScrollLockBtn: TButton;
  13.       Procedure SetScrollLockBtnClick(Sender: TObject);
  14.       Procedure ReleaseScrollLockBtnClick(Sender: TObject);
  15.    Private
  16.       { Private declarations }
  17.    Public
  18.       { Public declarations }
  19.    End;
  20.  
  21. Var
  22.    Form1 : TForm1;
  23.  
  24. Implementation
  25.  
  26. {$R *.DFM}
  27.  
  28. //----------------------------------------------------------------------
  29. // The Numlock key can be pressed this way under NT but NOT under W95!
  30. // The ScrollLock and CapsLock can be pressed this way under NT and W95
  31. // as well.
  32. // You can also simulate a PrintScreen (SnapShot).
  33. // See the Delphi help file for soft-pressing this key.
  34. // (Set the blinking cursor in the word: "keybd_event" and press: "F1")
  35. //----------------------------------------------------------------------
  36. Procedure SetNumLock(Bo : Boolean);
  37.  
  38. Var
  39.    keyState : TKeyBoardState;
  40.  
  41. Begin
  42. GetKeyboardstate(keyState);
  43. // keyState[VK_SCROLL] = 0 means the led is off
  44. // keyState[VK_SCROLL]  0 means the led is on
  45. If ( (Bo = True) and (keyState[VK_SCROLL] = 0) ) or
  46.    ( (Bo = False) and (keyState[VK_SCROLL]  0) ) then
  47.       Begin
  48.       // Simulate a depress
  49.       keybd_event(VK_SCROLL,45,KEYEVENTF_EXTENDEDKEY,0);
  50.       // Simulate a release
  51.       keybd_event(VK_SCROLL,45,KEYEVENTF_EXTENDEDKEY + KEYEVENTF_KEYUP,0);
  52.       End;
  53. End;
  54. //----------------------------------------------------------------------
  55. Procedure TForm1.SetScrollLockBtnClick(Sender: TObject);
  56.  
  57. Begin
  58. SetNumLock(TRUE);
  59. End;
  60. //----------------------------------------------------------------------
  61. Procedure TForm1.ReleaseScrollLockBtnClick(Sender: TObject);
  62.  
  63. Begin
  64. SetNumLock(FALSE);
  65. End;
  66. //----------------------------------------------------------------------
  67. End. {of Unit1}
  68. //======================================================================
  69. //delphi/8739

回复 "Delphi 操作键盘按下和释放操作"

这儿你可以回复上面这条便签

captcha