VB中如何实现在另外的窗口中点击或者按下快捷键的问题
发布网友
发布时间:2024-07-16 00:42
我来回答
共2个回答
热心网友
时间:2024-08-07 00:50
'1、在声明中加入下面代码
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
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 Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, _
ByVal lpClassName As String, _
ByVal nMaxCount As Long) _
As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetWindow Lib "user32" (ByVal hWnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, _
ByVal lpString As String, ByVal cch As Long) _
As Long
Private Const GW_CHILD = 5
Private Const GW_HWNDNEXT = 2
Private Const KEYEVENTF_EXTENDEDKEY = &H1
Private Const KEYEVENTF_KEYUP = &H2
Private Const WM_SETFOCUS = &H7
'2、关健代码如下:
Private Sub Timer1_Timer()
Dim lngDeskTopHandle As Long
Dim lngHand As Long
Dim strName As String * 255
Dim S As String
lngDeskTopHandle = GetDesktopWindow()
lngHand = GetWindow(lngDeskTopHandle, GW_CHILD)
Do While lngHand <> 0
GetWindowText lngHand, strName, Len(strName)
lngHand = GetWindow(lngHand, GW_HWNDNEXT)
If Left$(strName, 1) <> vbNullChar Then
S = Left$(strName, InStr(1, strName, vbNullChar))
If S = "你要查找的窗口标题" Then '开始模拟按crtl+s键
SetForegroundWindow lngHand
Sleep 200
SendMessage MainWnd, WM_SETFOCUS, 0&, 0&
keybd_event vbKeyControl, 0, KEYEVENTF_EXTENDEDKEY, 0
keybd_event vbKeyS, 0, KEYEVENTF_EXTENDEDKEY, 0
Sleep 100
keybd_event vbKeyControl, 0, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0
keybd_event vbKeyS, 0, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0
End If
End If
Loop
End Sub
热心网友
时间:2024-08-07 00:47
你说的已运行的程序或窗口是外部的还是内部的?
好像要调用API函数、、可以去网上搜下
我搜了一个给你看看,你举一反三就可以了
》》》vb怎么检测进程里某程序正在运行呢?
Const TH32CS_SNAPHEAPLIST = &H1
Const TH32CS_SNAPPROCESS = &H2
Const TH32CS_SNAPTHREAD = &H4
Const TH32CS_SNAPMODULE = &H8
Const TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST Or TH32CS_SNAPPROCESS Or TH32CS_SNAPTHREAD Or TH32CS_SNAPMODULE)
Const TH32CS_INHERIT = &H80000000
Const MAX_PATH As Integer = 260
Private Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szExeFile As String * MAX_PATH
End Type
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Private Declare Function Process32First Lib "kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Sub ExitProcess Lib "kernel32" (ByVal uExitCode As Long)
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Function exitproc(ByVal exefile As String) As Boolean
exitproc = False
Dim hSnapShot As Long, uProcess As PROCESSENTRY32
hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0&)
uProcess.dwSize = Len(uProcess)
r = Process32First(hSnapShot, uProcess)
Do While r
If Left$(uProcess.szExeFile, IIf(InStr(1, uProcess.szExeFile, Chr$(0)) > 0, InStr(1, uProcess.szExeFile, Chr$(0)) - 1, 0)) = exefile Then
exitproc = True
Exit Do
End If
'Retrieve information about the next process recorded in our system snapshot
r = Process32Next(hSnapShot, uProcess)
Loop
End Function
Private Sub Command1_Click()
MsgBox exitproc("vb6.exe")
End Sub
VB6:如何使在其他窗口按快捷键时生效?
Const MOD_SHIFT = &H4 Const GWL_WNDPROC = (-4) '注释:窗口函数的地址Dim key_preWinProc As Long ' 注释:用来保存窗口信息 Dim key_Modifiers As Long, key_uVirtKey As Long, key_idHotKey As Long Dim key_IsWinAddress As Boolean ' 注释:是否取得窗口信息的判断 Function k...
VB6:如何使在其他窗口按快捷键时生效?
注册系统热键 *** 窗体 *** Private Sub Form_Load() SetHotkey 1, "112", "Add"'F1 SetHotkey 2, "113", "Add"'F2 SetHotkey 3, "114", "Add"'F3 SetHotkey 4, "115", "Add"F4 SetHotkey 5, "Ctrl,112", "Add" 'ctrl+F1 End Sub Private Sub Form_Unload(Cancel As Integer...
vb按钮如何设置快捷键,
设置VB窗体中按扭快捷键的操作可以采用下面两种方法来实现:1、在按扭的Capion 属性设置标题的时候,前面增加 "&K"字符就可以,K代表的是你准备使用的Alt+键盘字符,如“&O.退出”,程序运行的时候按下 Alt+O 即执行该按扭的操作了 2、你可以利用该按扭所在的Form 窗体优先权获得键盘操作功能来激发你...
在VB中怎么实现把TEXT文档中的内容实现自动复制,并在指定窗口中通过点击...
如果是很多行的话,首先分析距离换行符的距离,然后将当前锁定位置~换行符位置之间的字符串,存入变量1,然后使用sendmessage命令将该字符串传送过去。快捷键的话,可以参考使用一个全局热键。然后实现程序的后台实现,每每按下热键的时候,就调用sendmessage命令。
运行vb程序的快捷键(vb打开程序代码窗口的快捷键)
vb程序运行的快捷键 、打开立即窗口的方法:第一种方法:在【视图】菜单中单击【立即窗口】。第二种方法:按 Ctrl+G快捷键打开。立即窗口:Debug窗口,Debug嘛,那么它用于检查各种错误的窗口。如果你写东西碰到了大问题迟迟不能解决建议你把立即窗口开开来。使用例子:1 有时候你要知道一个变量的值是...
VB有没有可能在主程序启动以后,不在主运行界面时,通过快捷键,运行...
Const 按键延时 = 400 / 检测延时 '按下400毫秒后重复 Sub CopyTxt(Txt As String)Clipboard.Clear Clipboard.SetText Txt End Sub Sub main()Do DoEvents Sleep 检测延时 If GetAsyncKeyState(vbKeyQ) And GetAsyncKeyState(vbKeyControl) Then End 'CTRL+Q 退出 If GetAsyncKeyState(vbKeyF2) Then...
用快捷键将HIDE的窗口显示出来,在VB中如何实现
提供你一个思路VB不会 就是在任意地方 写代码 截取按键 是截取 If key='Ctrl' and key='X' then 检测按键是否是你想要设置的快捷键 If form.show then 如果窗体是可见状态那么 form.hide 如果是你设置的快捷键且窗体当前可见 就隐藏窗体 Else form.show 如果是你设置的快捷键但窗体当前不...
vb怎么设置快捷键?
使用菜单编辑器,两种 方法使用快捷键 1.在名称后加_快捷键(如:文件_(F) ),运行时按下ALT+F,就可以打开该菜单,该方法适用一层层打开菜单 2.在编辑菜单项时直接指定,该方法适用直接打开想要的功能 本回答由提问者推荐 举报| 答案纠错 | 评论 7 10 fandyfandy0 采纳率:46% 来自:芝麻团 擅长: VB 其他...
vb编程 文本框 中怎么使用快捷键
Me.KeyPreview = True '上面语句使窗体先于控件拦截键盘事件,这样只要窗体是活动的,'用户无论何时按键,都会响应你设置的快捷键 End Sub Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)'设置快捷键 Enter+Shift 的代码 If KeyCode = 13 And Shift = 1 Then MsgBox "按了 Enter...
VB中如何为程序设置快捷键
运行后程序自动隐藏,按快捷键自动出现 '第一步:'新建一个窗口,将以下代码复制进去 注册热键为:'Ctrl+Alt+P Private Sub Form_Load()form1.hide Dim ret As Long preWinProc = GetWindowLong(Me.hwnd,GWL_WNDPROC)ret = SetWindowLong(Me.hwnd,GWL_WNDPROC,AddressOf Wndproc)idHotKey = 1 Mo...