我想用msghook动态监测某一window上是否出现某些字样,是的话就对window发送如F1,A,B等的键盘指令,请教如何编程?

zhongyaosen 2003-12-22 04:58:47
我想用msghook动态监测某一window上是否出现某些字样,是的话就对window发送如F1,A,B等的键盘指令,请教如何编程?
...全文
6 点赞 收藏 8
写回复
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhongyaosen 2003-12-23
window是c/s中的client window,文字出现是随机的,估计不是标准控件,我想要用鼠标定坐标和定时copy某位置上是否出现某些字,请教如何编程?
另外我用msghook,
WinText = "client"
Handle = FindWindow(vbNullString, WinText)

Msghook1.HwndHook = Handle
的时候,运行时益出,请教原因,要怎么编?
回复
online 2003-12-23
Msghook1.HwndHook = form1.hwnd
将msghook1绑顶到form1上

Handle = FindWindow(vbNullString, WinText)??
这个应该是空的

然后在拦截消息


回复
zhongyaosen 2003-12-23
如果可以截取到server发给client的文字信息,就最好了,可以直接分析文字,不用那么麻烦
回复
imur 2003-12-22
请教 rainstormmaster(rainstormmaster) 大侠及其他大侠:
(1)Const WM_CHAR = &H102
Const VK_RETURN = &HD
Const VK_H = 72
Const VK_E = 69
Const VK_L = 76
Const VK_O = 79---分别是什么意思?为什么要这样定义?
(2)这三句话:
SendMessage Text1.hwnd, WM_CHAR, Asc("a"), ByVal 0&
keybd_event VK_H, 0, 0, 0 ' press H
keybd_event VK_H, 0, KEYEVENTF_KEYUP, 0 ' release H
--各个参数分别是什么意思?这句话是什么意思?


请教请教!
回复
flc 2003-12-22
关注
学习
回复
rainstormmaster 2003-12-22
把问题描述得再详细一些

//动态监测某一window上是否出现某些字样

在什么位置?如果是标准控件的话还好办,如果是用api函数画上去的,那麻烦就大了

模拟键盘操作可用vb提供的SendKeys,也可用sendmessage发送wm_char消息,或使用keybd_event

发送wm_char消息的例子

Option Explicit
Private Const WM_CHAR = &H102
Private Const VK_RETURN = &HD
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Sub Command1_Click()
SendMessage Text1.hwnd, WM_CHAR, Asc("a"), ByVal 0&
End Sub


使用keybd_event的例子:
Const VK_H = 72
Const VK_E = 69
Const VK_L = 76
Const VK_O = 79
Const KEYEVENTF_EXTENDEDKEY = &H1
Const KEYEVENTF_KEYUP = &H2
Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Sub Form_KeyPress(KeyAscii As Integer)
'Print the key on the form
Me.Print Chr$(KeyAscii);
End Sub
Private Sub Form_Paint()
'Clear the form
Me.Cls
keybd_event VK_H, 0, 0, 0 ' press H
keybd_event VK_H, 0, KEYEVENTF_KEYUP, 0 ' release H
keybd_event VK_E, 0, 0, 0 ' press E
keybd_event VK_E, 0, KEYEVENTF_KEYUP, 0 ' release E
keybd_event VK_L, 0, 0, 0 ' press L
keybd_event VK_L, 0, KEYEVENTF_KEYUP, 0 ' release L
keybd_event VK_L, 0, 0, 0 ' press L
keybd_event VK_L, 0, KEYEVENTF_KEYUP, 0 ' release L
keybd_event VK_O, 0, 0, 0 ' press O
keybd_event VK_O, 0, KEYEVENTF_KEYUP, 0 ' release O
End Sub
回复
jhzhou882 2003-12-22
SendKeys "{F1}"
SendKeys "A"
回复
jhzhou882 2003-12-22
发键盘指令用
SENDKEYS就可以吧
回复
发动态
发帖子
VB基础类
创建于2007-09-28

7453

社区成员

VB 基础类
申请成为版主
社区公告
暂无公告