博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Delphi 发送按键
阅读量:7081 次
发布时间:2019-06-28

本文共 1703 字,大约阅读时间需要 5 分钟。

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博客,转载请标明出处:

你可能感兴趣的文章
Python - 几个注意的要点
查看>>
thymeleaf关于js的一些坑(数组定义)
查看>>
车联网上云最佳实践(一)
查看>>
使用Keras进行深度学习:(五)RNN和双向RNN讲解及实践
查看>>
graphviz 安装和入门
查看>>
Apache Lucene 8.0.0 发布,Java 全文搜索引擎
查看>>
Idea取消Could not autowire. No beans of 'xxxx' type found的错误提示
查看>>
一文读懂JDK1.7,JDK1.8,JDK1.9的hashmap,hashtable,concurrenthashmap及他们的区别
查看>>
vue2.0组件间传值的方法汇总
查看>>
C#中如何调整图像大小
查看>>
数据质量和特征分析
查看>>
YII2 配置gii之后页面404 解决 2点=1 要加载model,2 要设置环境为dev,如下截图 3次要---有时候可能需要 执行composer dump-autoload 重新加载类...
查看>>
不设外键:来看看上次预留的连接查询接口
查看>>
oracle函数:instr
查看>>
[搬运]什么叫幂等性?
查看>>
Stegosuite,图片隐写术
查看>>
MikroTik RouterOS安装方法收集(转)
查看>>
您的业务需要软件定义网络的五个原因
查看>>
springcloud应用程序上下文层次结构
查看>>
人类社会发展与信息网络化
查看>>