- unit sndkey32;
- interface
- Uses SysUtils, Windows, Messages;
- Function SendKeys(SendKeysString : PChar; Wait : Boolean) : Boolean;
- function AppActivate(WindowName : PChar) : boolean;
- {Buffer for working with PChar's}
- const
- WorkBufLen = 40;
- var
- WorkBuf : array[0..WorkBufLen] of Char;
- implementation
- type
- THKeys = array[0..pred(MaxLongInt)] of byte;
- var
- AllocationSize : integer;
- (*
- Converts a string of characters and key names to keyboard events and
- passes them to Windows.
- Example syntax:
- SendKeys('abc123{left}{left}{left}def{end}456{left 6}ghi{end}789', True);
- *)
- Function SendKeys(SendKeysString : PChar; Wait : Boolean) : Boolean;
- type
- WBytes = array[0..pred(SizeOf(Word))] of Byte;
- TSendKey = record
- Name : ShortString;
- VKey : Byte;
- end;
- const
- {Array of keys that SendKeys recognizes.
- If you add to this list, you must be sure to keep it sorted alphabetically
- by Name because a binary search routine is used to scan it.}
- MaxSendKeyRecs = 41;
- SendKeyRecs : array[1..MaxSendKeyRecs] of TSendKey =
- (
- (Name:'BKSP'; VKey:VK_BACK),
- (Name:'BS'; VKey:VK_BACK),
- (Name:'BACKSPACE'; VKey:VK_BACK),
- (Name:'BREAK'; VKey:VK_CANCEL),
- (Name:'CAPSLOCK'; VKey:VK_CAPITAL),
- (Name:'CLEAR'; VKey:VK_CLEAR),
- (Name:'DEL'; VKey:VK_DELETE),
- (Name:'DELETE'; VKey:VK_DELETE),
- (Name:'DOWN'; VKey:VK_DOWN),
- (Name:'END'; VKey:VK_END),
- (Name:'ENTER'; VKey:VK_RETURN),
- (Name:'ESC'; VKey:VK_ESCAPE),
- (Name:'ESCAPE'; VKey:VK_ESCAPE),
- (Name:'F1'; VKey:VK_F1),
- (Name:'F10'; VKey:VK_F10),
- (Name:'F11'; VKey:VK_F11),
- (Name:'F12'; VKey:VK_F12),
- (Name:'F13'; VKey:VK_F13),
- (Name:'F14'; VKey:VK_F14),
- (Name:'F15'; VKey:VK_F15),
- (Name:'F16'; VKey:VK_F16),
- (Name:'F2'; VKey:VK_F2),
- (Name:'F3'; VKey:VK_F3),
- (Name:'F4'; VKey:VK_F4),
- (Name:'F5'; VKey:VK_F5),
- (Name:'F6'; VKey:VK_F6),
- (Name:'F7'; VKey:VK_F7),
- (Name:'F8'; VKey:VK_F8),
- (Name:'F9'; VKey:VK_F9),
- (Name:'HELP'; VKey:VK_HELP),
- (Name:'HOME'; VKey:VK_HOME),
- (Name:'INS'; VKey:VK_INSERT),
- (Name:'LEFT'; VKey:VK_LEFT),
- (Name:'NUMLOCK'; VKey:VK_NUMLOCK),
- (Name:'PGDN'; VKey:VK_NEXT),
- (Name:'PGUP'; VKey:VK_PRIOR),
- (Name:'PRTSC'; VKey:VK_PRINT),
- (Name:'RIGHT'; VKey:VK_RIGHT),
- (Name:'SCROLLLOCK'; VKey:VK_SCROLL),
- (Name:'TAB'; VKey:VK_TAB),
- (Name:'UP'; VKey:VK_UP)
- );
- {Extra VK constants missing from Delphi's Windows API interface}
- VK_NULL=0;
- VK_SemiColon=186;
- VK_Equal=187;
- VK_Comma=188;
- VK_Minus=189;
- VK_Period=190;
- VK_Slash=191;
- VK_BackQuote=192;
- VK_LeftBracket=219;
- VK_BackSlash=220;
- VK_RightBracket=221;
- VK_Quote=222;
- VK_Last=VK_Quote;
- ExtendedVKeys : set of byte =
- [VK_Up,
- VK_Down,
- VK_Left,
- VK_Right,
- VK_Home,
- VK_End,
- VK_Prior, {PgUp}
- VK_Next, {PgDn}
- VK_Insert,
- VK_Delete];
- const
- INVALIDKEY = $FFFF {Unsigned -1};
- VKKEYSCANSHIFTON = $01;
- VKKEYSCANCTRLON = $02;
- VKKEYSCANALTON = $04;
- UNITNAME = 'SendKeys';
- var
- UsingParens, ShiftDown, ControlDown, AltDown, FoundClose : Boolean;
- PosSpace : Byte;
- I, L : Integer;
- NumTimes, MKey : Word;
- KeyString : String[20];
- procedure DisplayMessage(Message : PChar);
- begin
- MessageBox(0,Message,UNITNAME,0);
- end;
- function BitSet(BitTable, BitMask : Byte) : Boolean;
- begin
- Result:=ByteBool(BitTable and BitMask);
- end;
- procedure SetBit(var BitTable : Byte; BitMask : Byte);
- begin
- BitTable:=BitTable or Bitmask;
- end;
- Procedure KeyboardEvent(VKey, ScanCode : Byte; Flags : Longint);
- var
- KeyboardMsg : TMsg;
- begin
- 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 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 SendKeyUp(VKey: Byte);
- var
- ScanCode : Byte;
- begin
- ScanCode:=Lo(MapVirtualKey(VKey,0));
- If (VKey in ExtendedVKeys)then
- KeyboardEvent(VKey, ScanCode, KEYEVENTF_EXTENDEDKEY and KEYEVENTF_KEYUP)
- else KeyboardEvent(VKey, ScanCode, KEYEVENTF_KEYUP);
- end;
- Procedure SendKey(MKey: Word; NumTimes : Word; GenDownMsg : Boolean);
- begin
- If (BitSet(Hi(MKey),VKKEYSCANSHIFTON)) then SendKeyDown(VK_SHIFT,1,False);
- If (BitSet(Hi(MKey),VKKEYSCANCTRLON)) then SendKeyDown(VK_CONTROL,1,False);
- If (BitSet(Hi(MKey),VKKEYSCANALTON)) then SendKeyDown(VK_MENU,1,False);
- SendKeyDown(Lo(MKey), NumTimes, GenDownMsg);
- If (BitSet(Hi(MKey),VKKEYSCANSHIFTON)) then SendKeyUp(VK_SHIFT);
- If (BitSet(Hi(MKey),VKKEYSCANCTRLON)) then SendKeyUp(VK_CONTROL);
- If (BitSet(Hi(MKey),VKKEYSCANALTON)) then SendKeyUp(VK_MENU);
- end;
- {Implements a simple binary search to locate special key name strings}
- Function StringToVKey(KeyString : ShortString) : Word;
- var
- Found, Collided : Boolean;
- Bottom, Top, Middle : Byte;
- begin
- Result:=INVALIDKEY;
- Bottom:=1;
- Top:=MaxSendKeyRecs;
- Found:=false;
- Middle:=(Bottom+Top) div 2;
- Repeat
- Collided:=((Bottom=Middle) or (Top=Middle));
- If (KeyString=SendKeyRecs[Middle].Name) then begin
- Found:=True;
- Result:=SendKeyRecs[Middle].VKey;
- end else begin
- If (KeyString>SendKeyRecs[Middle].Name) then Bottom:=Middle
- else Top:=Middle;
- Middle:=(Succ(Bottom+Top)) div 2;
- end;
- Until (Found or Collided);
- If (Result=INVALIDKEY) then DisplayMessage('Invalid Key Name');
- end;
- procedure PopUpShiftKeys;
- begin
- If (not UsingParens) then begin
- If ShiftDown then SendKeyUp(VK_SHIFT);
- If ControlDown then SendKeyUp(VK_CONTROL);
- If AltDown then SendKeyUp(VK_MENU);
- ShiftDown:=false;
- ControlDown:=false;
- AltDown:=false;
- end;
- end;
- begin
- AllocationSize:=MaxInt;
- Result:=false;
- UsingParens:=false;
- ShiftDown:=false;
- ControlDown:=false;
- AltDown:=false;
- I:=0;
- L:=StrLen(SendKeysString);
- If (L>AllocationSize) then L:=AllocationSize;
- If (L=0) then Exit;
- While (I<L) do begin
- case SendKeysString[I] of
- '(' : begin
- UsingParens:=True;
- Inc(I);
- end;
- ')' : begin
- UsingParens:=False;
- PopUpShiftKeys;
- Inc(I);
- end;
- '%' : begin
- AltDown:=True;
- SendKeyDown(VK_MENU,1,False);
- Inc(I);
- end;
- '+' : begin
- ShiftDown:=True;
- SendKeyDown(VK_SHIFT,1,False);
- Inc(I);
- end;
- '^' : begin
- ControlDown:=True;
- SendKeyDown(VK_CONTROL,1,False);
- Inc(I);
- end;
- '{' : begin
- NumTimes:=1;
- If (SendKeysString[Succ(I)]='{') then begin
- MKey:=VK_LEFTBRACKET;
- SetBit(Wbytes(MKey)[1],VKKEYSCANSHIFTON);
- SendKey(MKey,1,True);
- PopUpShiftKeys;
- Inc(I,3);
- Continue;
- end;
- KeyString:='';
- FoundClose:=False;
- While (I<=L) do begin
- Inc(I);
- If (SendKeysString[I]='}') then begin
- FoundClose:=True;
- Inc(I);
- Break;
- end;
- KeyString:=KeyString+Upcase(SendKeysString[I]);
- end;
- If (Not FoundClose) then begin
- DisplayMessage('No Close');
- Exit;
- end;
- If (SendKeysString[I]='}') then begin
- MKey:=VK_RIGHTBRACKET;
- SetBit(Wbytes(MKey)[1],VKKEYSCANSHIFTON);
- SendKey(MKey,1,True);
- PopUpShiftKeys;
- Inc(I);
- Continue;
- end;
- PosSpace:=Pos(' ',KeyString);
- If (PosSpace<>0) then begin
- NumTimes:=StrToInt(Copy(KeyString,Succ(PosSpace),Length(KeyString)-PosSpace));
- KeyString:=Copy(KeyString,1,Pred(PosSpace));
- end;
- If (Length(KeyString)=1) then MKey:=vkKeyScan(KeyString[1])
- else MKey:=StringToVKey(KeyString);
- If (MKey<>INVALIDKEY) then begin
- SendKey(MKey,NumTimes,True);
- PopUpShiftKeys;
- Continue;
- end;
- end;
- '~' : begin
- SendKeyDown(VK_RETURN,1,True);
- PopUpShiftKeys;
- Inc(I);
- end;
- else begin
- MKey:=vkKeyScan(SendKeysString[I]);
- If (MKey<>INVALIDKEY) then begin
- SendKey(MKey,1,True);
- PopUpShiftKeys;
- end else DisplayMessage('Invalid KeyName');
- Inc(I);
- end;
- end;
- end;
- Result:=true;
- PopUpShiftKeys;
- end;
- {AppActivate
- This is used to set the current input focus to a given window using its
- name. This is especially useful for ensuring a window is active before
- sending it input messages using the SendKeys function. You can specify
- a window's name in its entirety, or only portion of it, beginning from
- the left.
- }
- var
- WindowHandle : HWND;
- function EnumWindowsProc(WHandle: HWND; lParam: LPARAM): BOOL; export; stdcall;
- const
- MAX_WINDOW_NAME_LEN = 80;
- var
- WindowName : array[0..MAX_WINDOW_NAME_LEN] of char;
- begin
- {Can't test GetWindowText's return value since some windows don't have a title}
- GetWindowText(WHandle,WindowName,MAX_WINDOW_NAME_LEN);
- Result := (StrLIComp(WindowName,PChar(lParam), StrLen(PChar(lParam))) <> 0);
- If (not Result) then WindowHandle:=WHandle;
- end;
- function AppActivate(WindowName : PChar) : boolean;
- begin
- try
- Result:=true;
- WindowHandle:=FindWindow(nil,WindowName);
- If (WindowHandle=0) then EnumWindows(@EnumWindowsProc,Integer(PChar(WindowName)));
- If (WindowHandle<>0) then begin
- SendMessage(WindowHandle, WM_SYSCOMMAND, SC_HOTKEY, WindowHandle);
- SendMessage(WindowHandle, WM_SYSCOMMAND, SC_RESTORE, WindowHandle);
- end else Result:=false;
- except
- on Exception do Result:=false;
- end;
- end;
- end.
相关推荐
delphi控件集合(sndkey32,videocap,canonocx)
delphi 常用控件集合 键盘控制:sndkey32 摄像头控制:videocap 佳能控件:canonocx
Delphi中的SendKeys函数
用过Visual Basic等编程语言的朋友们一定对其SendKeys函数非常熟悉。利用该函数可以把一个字符串发送到目标窗口(比如记事本)或控件(比如一个Edit控件)中,就好像是在目标窗口或控件中输入这个字符串一样。但是,在Delphi中却没有为我们提供这样的函数。其实,Borland的工程师们早就提供了一个方便的方法:在Delphi5.0企业版的安装盘的infoExtrasSendKeys文件
WtsApi32.pas
Windows Terminal Server SDK APIs
Delphi中的SendKeys函数 - sndKey32.Pas 下载
<br />http://www.wesoho.com/soft/down/sndkey32.rar<br />用过Visual Basic等编程语言的朋友们一定对其SendKeys函数非常熟悉。利用该函数可以把一个字符串发送到目标窗口(比如记事本)或控件(比如一个Edit控件)中,就好像是在目标窗口或控件中输入这个字符串一样。但是,在Delphi中却没有为我们提供这样的函数。其实,Borland的工程师们早就提供了一个方便的方法:在Delphi5.0企业版的安装盘的/info/Extras/SendKey
SendKeys模拟键盘输入实例源代码
SendKeys模拟键盘输入实例源代码
lkJSOn.pas的改进版, 支持中文, 非常不错(uLkJSON.pas)
lkJSOn.pas的改进版, 支持中文, 非常不错(uLkJSON.pas)
Sendkey.pas
unit sndkey32; interface uses SysUtils, Windows, Messages; function SendKeys(SendKeysString: PChar; Wait: Boolean): Boolean; function AppActivate(WindowName: PChar): boolean; {Buffer for working w
Delphi发送中文字符给激活窗口文本框
Delphi发送中文字符给激活窗口文本框
delphi windows操作
输入 procedure TypeKeyString(s: string); var c: Char; i: integer; off: integer; vkw: Word; begin for i := 1 to Length(s) do begin c := s[i]; if (c < #128) then...
用Spirent Test Center测试交换机Head of Line(HOL)Blocking
测试目的:设备执行拥塞控制,使非阻塞端口不受阻塞端口影响 预设条件:在RFC2889里按以下步骤设置,端口1和端口3同时向端口4发送数据包,端口1向端口2发送数据包 测试步骤:运行设置好的RFC2889 测试结果:所有frame size都显示没有Head of Line(HOL),即非阻塞端口不受阻塞端口所影响 ...
从零到一:基于STM8的125KHz RFID读卡器实现与曼彻斯特码解析实战
本文详细介绍了基于STM8单片机的125KHz RFID读卡器实现过程,重点解析了曼彻斯特码的编码原理与解码算法。通过硬件电路设计、软件实现及性能优化,帮助开发者低成本构建稳定读取EM4100卡片的系统,适用于门禁、考勤等应用场景。
向指定窗口发送键击消息Delphi
unit SendKeys; interface uses Windows, SysUtils; const SK_BKSP = #8; SK_TAB = #9; SK_ENTER = #13; SK_ESC = #27; SK_ADD = #107; SK_SUB = #109; SK_F1 = #
团子杂记:SAP收入确认工具RAR(Revenue Recognition&Reporting)在新收入准则下的应用
SAP收入确认工具RAR知识分享
webbrowers用法集
c# webbrowser新窗口 浏览次数:621次悬赏分:50 | 解决时间:2010-4-28 06:58 | 提问者:jeogegxs 我用的是.net2005(C#)中AxSHDocVw.AxWebBrowser的webbrowser控件。我现在想在点击链接或按钮弹出新窗口时,webbrowser的大小和弹出窗口页面设置的窗口大小一致(如javascript里window.open里写的w...
第一篇:常见CAN错误帧及其排查方向
在本文中主要阐述各类错误帧的形成原因以及在使用同星硬件设备出现错误帧时,应当 如何进行排查并消除错误帧。在 CAN 总线通信中,通常遇见的错误帧主要为以下五种,其 分别是:bit error、ACK error、stuff error、CRC error 以及 form error。
CA(载波聚合)
文章目录CA基本概念1. CA分类2. Pcell、Scell以及Serving CellPcell(Primary Cell)Scell(Secondary Cell)3. Pcell、Scell部署场景场景1场景2场景3场景44. CA的协议控制4.1 Camping/Connetion Establishment:4.2 CC Management/SCell Addition/Release:4.3 Handover/Measurements:4.4 SCell激活 CA基本概念 CA也就是我们中文
老文章——TWebBrowser编程简述
引 言 这篇文章最先发表于2000年07月25日,最后一次修改是在2001年02月07日。这里再次贴出的目的,一是作为前一阶段的完结,所以文章中的错误都不作修改;二是希望作为一个新的起点。我准备整理一下至今所积累的浏览器编程的知识,比较完整地写出来,与网友共勉。TWebBrowser编程简述摘要:Delphi 3开始有了TWebBrowser构件,不过那时是以ActiveX控件的形式
23、微波电路中的过孔、过孔围栏与接地焊盘建模分析
本文详细分析了微波电路设计中过孔、过孔围栏及接地焊盘的建模与优化方法。探讨了过孔模型的发展及其电感与电容特性,通过场求解器和集总元件模型提高建模精度。此外,分析了过孔隔离围栏在改善信号隔离中的作用,并通过2.5D和3D电磁仿真验证其效果。最后,研究了接地焊盘中过孔布局对电路稳定性的影响,提出了优化过孔位置以消除谐振和杂散振荡的方法。文章为微波电路设计提供了重要的理论支持和实践指导。
delphi中webbrowser的用法
delphi中webbrowser的用法
B3640 T3 句子反转
要求将这些单词倒序输出。而且对于每个单词,如果是小写词,应当转为大写;如果是大写词,应当转为小写;如果是自然数,应该倒转输出。给定一行句子,每个词之间用空格隔开,要么是全小写英文单词,要么是全大写英文单词,要么是自然数。第一次做的时候0分,两个小时没做出来。仅一行,表示程序对句子的处理结果。仅一行,即需要反转的句子。
[Python图像处理] 十九.图像分割之基于K-Means聚类的区域分割
前面的文章讲解了图像锐化和边缘提取技术,该篇文章将开始围绕图像分割进行讲解。图像分割就是把图像分成若干个特定的、具有独特性质的区域并提出感兴趣目标的技术和过程。 本篇文章主要讲解基于理论的图像分割方法,通过K-Means聚类算法实现图像分割或颜色分层处理。基础性文章,希望对你有所帮助。 1.K-Means原理 2.K-Means聚类分割灰度图像 3.K-Means聚类对比分割彩色图像
1852




被折叠的 条评论
为什么被折叠?



