• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Delphi发送按键

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
利用Delphi编写Socket通信程序发布时间:2022-07-18
下一篇:
[转载]matlab坐标轴设置发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap