Home > Web Front-end > JS Tutorial > body text

javascript利用控件对windows的操作实现原理与应用_javascript技巧

WBOY
Release: 2016-05-16 17:45:44
Original
1382 people have browsed it

复制代码 代码如下:

//windows 98

//win2000 or xp


sendKeys(args[])方法详解(VB):
vb.net中使用sendkeys遥控:
大家在vb6中都用过sendkeys,幕通过发送键盘的事件间接地控制外部程序,是有遥控之说。
我在vb7中却发现这个不能用了, 也就不了了之,后来一次在查阅msdn的时候竟看到了这个,是以尝试了一下,竟然旧貌新颜,还是一样好用。

主要是在system.winforms族中找到sendkeys 使用方法同vb6
键:一般的字符键如下输入”a” “b” “c”………………”z”等,如果要连续按下两个以上就使用”ab”的形式如果同时按下ab就使用括号如”(ab)”
如果是功能键,就放到大括号中如“{f4}” 另:用+代表shift,用^代表ctrl,用%代表alt
如“+a”表示按下shift同时按a
下面是一个例子
dim sdstr as system.winforms.sendkeys
sdstr.send("%{f4}") 发送alt+f4
下面这个代码在按下button2以后转移焦点到下一个控件,使按钮能按下又不能按受焦点.
复制代码 代码如下:

protected sub button2_click(byval sender as object, byval e
as system.eventargs)
dim sdstr as system.winforms.sendkeys
sdstr.send("{tab}")
end sub

下面使用sendwait,使用的方法同上,不过执行这个过程会等待到发送的键执行完成以后,再继续执行后面的代码.
复制代码 代码如下:

protected sub button2_click(byval sender as object, byval e
as system.eventargs)
dim sdstr as system.winforms.sendkeys
'sdstr.send("{tab}")
sdstr.sendwait("{tab}")
end sub

vb.net中使用shell调用外部程序:
复制代码 代码如下:

shell(pathname as string,[style as
microsoft.visualbasic.appwinstyle=2],[wait as
boolean=false],[timeout as integer=-1]) as integer

调用资源管理器
复制代码 代码如下:

dim pid as integer
pid = shell("explorer.exe http://vbnetcn.126.com",
microsoft.visualbasic.appwinstyle.normalfocus, true)

调用默认程序
复制代码 代码如下:

dim pid as integer
pid = shell("start.exe mailto:vbnetcn@163.com",
microsoft.visualbasic.appwinstyle.hide, true)

使用microsoft.visualbasic.appwinstyle.hide参数是为了隐藏程序
运行时跳出的dos窗口。

sendkeys是个模拟键盘消息的函数,我们暂且不谈windows消息驱动来单纯的考虑sendkey这个函数
sendkeys既然模拟的是键盘消息,那么他就只能模拟键盘上能输入的消息,比如说
sendkeys("abcd")
其实并不是这个脚本把"abcd"这个字串发出去
而是模拟键盘的输入,相当于键盘先点击了a再点击了b在点击了c。。。。。
加入发送的按键消息被qq的聊天框受到了,那么我们都知道他的处理方法是把英文字母显示到聊天框中
但是我们发现,加入用sendkey模拟输入汉字的话,似乎就不现实了,因为键盘上没有中文按键。。。。
但是我们有想输入我们汉字的聊天内容,那么我们可以怎么办呢?

从原理说起哈,sendkey其实就是个在windows中发送特定消息的一个函数(我猜他发送的是WM_SYSKEYDOWN的消息,我没有测试过哈^_^)

我们假如要发送汉字的聊天框的内容的话,我们也要从windows消息机制下手,先找到聊天消息的句柄(可以利用findwindow函数或者用spy工具哈),然后在找到上面的聊天框的句柄,接着我们就可以想这个句柄发送WM_SETTEXT的消息了。
粗略的
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!