zoukankan      html  css  js  c++  java
  • Delphi 发送按键

    const
    ExtendedVKeys : set of byte =
          [VK_Up,VK_Down,VK_Left,VK_Right,VK_Home,VK_End,VK_Prior, {Pg Up} VK_Next, {PgDn}VK_Insert,VK_Delete];
    //////////////////////发送按键
    procedure SendCardNo(CardNo:String);
     var
      i :integer;
    begin
     for i:=1 to length(CardNo) do
     begin
        SendKeyDown(vkKeyScan(CardNo[i]),1, False);
     end;


    end;
    procedure SendKeysBack(Key:char);
    begin

      SendKeyDown(vkKeyScan(Key),1, False);

    end;


    Procedure SendKeyDown(VKey: Byte;NumTimes : Word;GenUpMsg : Boolean);
     var
       Cnt : Word;
       ScanCode : Byte;
       NumState : Boolean;
       KeyBoardState : TKeyboardState;
      begin
      If (VKey=VK_NUMLOCK) then
        begin
         NumState:=ByteBool(GetKeyState(VK_NUMLOCK) and 1);
         GetKeyBoardState(KeyBoardState);
       If NumState then
         KeyBoardState[VK_NUMLOCK]:=(KeyBoardState[VK_NUMLOCK] and not 1)
       else
         KeyBoardState[VK_NUMLOCK]:=(KeyBoardState[VK_NUMLOCK] or 1);
         SetKeyBoardState(KeyBoardState);
         exit;
       end;
      ScanCode:=Lo(MapVirtualKey(VKey,0));
      For Cnt:=1 to NumTimes do
        If (VKey in ExtendedVKeys)then
        begin
          KeyboardEvent( VKey, ScanCode, KEYEVENTF_EXTENDEDKEY);
          If (GenUpMsg ) then
           KeyboardEvent( VKey, ScanCode, KEYEVENTF_EXTENDEDKEY or KEYEVENTF_KEYUP)
        end
        else
        begin
          KeyboardEvent(VKey, ScanCode, 0) ;
          If (GenUpMsg) then
            KeyboardEvent(VKey, ScanCode, KEYEVENTF_KEYUP);
        End;
     end;
     Procedure KeyboardEvent(VKey, ScanCode : Byte;Flags : Longint);
     var
       KeyboardMsg : TMsg;
       Wait :boolean;
     begin
     wait :=true;
      keybd_event(VKey, ScanCode, Flags,0);
      If (Wait) then While (
          PeekMessage(KeyboardMsg,0,WM_KEYFIRST, WM_KEYLAST, PM_REMOVE)) do
            begin
             TranslateMessage(KeyboardMsg);
             DispatchMessage( KeyboardMsg);
            end;
      end;
    procedure SetCardLength(value: integer);
    begin
    CardLength:=Value;
    end;

    procedure SetSendKey(value: boolean);
    begin
    SendKey:=Value;
    end;

    本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/lostcity1/archive/2006/03/23/636077.aspx

  • 相关阅读:
    MYSQL中排序
    编写一个 SQL 查询,获取 Employee 表中第二高的薪水(Salary)
    job1
    python中对于数组的操作
    python中将字符串转为字典类型
    python中的周几
    python 链接redis 获取对应的值
    jenkins 设置定时任务规则
    如何安全close go 的channel
    [转]
  • 原文地址:https://www.cnblogs.com/MaxWoods/p/1612247.html
Copyright © 2011-2022 走看看