当前位置:编程学习 > VB >>

VB API keybd_event

Private Declare Sub keybd_event Lib "user32" Alias "keybd_event" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
谁能举个小例子帮我了解这个函数
答案:在VB中使用API是很麻烦的,如果在passcal borland delphi 下使用,跟本不需要声名,
而且模拟键盘也很简单。直接发送键码就行了。
比如procedure TForm1.Button1Click(Sender: TObject);
var npad:HWND;
i,j:integer;
begin
//须先閞NotePad
Npad := FindWindow(nil, '未命名 - 记事本');
if npad <> 0 then begin
BringWindowToTop(Npad); //使其成为focus之window
for j:=1 to 5 do begin
for i := ord('A') to ord('Z') do begin //大小写均同
keybd_event(i, 0, 0, 0); //keydown此键
keybd_event(i, 0, KEYEVENTF_KEYUP, 0); //keyup
keybd_event(VK_SHIFT, 0, 0, 0); //按着Shift ,使成为大写
keybd_event(I, 0, 0, 0); //keydown
keybd_event(I, 0, KEYEVENTF_KEYUP, 0); //keyup
keybd_event(VK_SHIFT, 0, KEYEVENTF_KEYUP, 0); //放开shift
end;
keybd_event(VK_RETURN, 0, 0, 0); //换行
keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0);
end;
end;

上一个:VB如何播放背景音乐
下一个:VB获取文件夹路径

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,