用VB编写按键程序

用VB编写模仿按键Alt+Tab的程序,要过程要使Form窗口隐藏,把WindowState设为1-Minimized... 用VB编写模仿按键Alt+Tab的程序,要过程
要使Form窗口隐藏,把WindowState设为1 - Minimized
展开
 我来答
gujin170
2008-08-06 · TA获得超过937个赞
知道小有建树答主
回答量:1030
采纳率:66%
帮助的人:334万
展开全部
'模块
Option Explicit

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal _
hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg _
As Long, ByVal wParam As Long, ByVal lParam As Any) As Long
Private Const WM_GETTEXT = &HD
Private Const WM_GETTEXTLENGTH = &HE

' Type Declarations
Private Type KBDLLHOOKSTRUCT
vkCode As Long
End Type

' Win32 API
Private Declare Function SetWindowsHookEx Lib "user32" _
Alias "SetWindowsHookExA" _
(ByVal idHook As Long, _
ByVal lpfn As Long, _
ByVal hmod As Long, _
ByVal dwThreadId As Long) As Long

Private Declare Function UnhookWindowsHookEx Lib "user32" _
(ByVal hHook As Long) As Long

Private Declare Function CallNextHookEx Lib "user32" _
(ByVal hHook As Long, _
ByVal nCode As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long

Private Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" _
(pDest As Any, _
pSource As Any, _
ByVal cbLength As Long)

' Constants
Private Const WH_KEYBOARD_LL = 13& ' Hook Flag
Private Const HC_ACTION = 0& ' Keyboard Process Message

' Variables
Private m_hLLKeyboardHook As Long ' The hook object
Public g_bInterceptKeys As Boolean ' Flag

Dim hform As Long
Dim hnextform As Long
Dim hpass As Long
Dim cLong As Long
Dim astr As String * 256

Public Function LowLevelKeyboardProc(ByVal nCode As Long, ByVal wParam As Long, _
ByVal lParam As Long) As Long

' Set up the hook object
Static tKeyboardHook As KBDLLHOOKSTRUCT

If nCode = HC_ACTION Then
Call CopyMemory(tKeyboardHook, ByVal lParam, Len(tKeyboardHook))

' Display some info on the form

If tKeyboardHook.vkCode = 121 Then
SendKeys "%{TAB}", True '发送ALT+TAB
Call UnSetSystemWideKeyboardHook
Else
Exit Function
End If

End If

If g_bInterceptKeys Then
' Intercept the key and don't pass it along the hook chain
LowLevelKeyboardProc = 1
Exit Function
End If

' If the message is not one we want to trap, pass it along
' through the hook chain to the intended app
LowLevelKeyboardProc = CallNextHookEx(m_hLLKeyboardHook, nCode, wParam, lParam)

End Function

Public Function SetSystemWideKeyboardHook() As Long

' Hook into the keyboard process

' Specifying 0 for the last parameter (dwThreadId) indicates a system wide
' hook

If m_hLLKeyboardHook = 0 Then
m_hLLKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf LowLevelKeyboardProc, App.hInstance, 0&)
End If

If m_hLLKeyboardHook = 0 Then
SetSystemWideKeyboardHook = 0
Else
SetSystemWideKeyboardHook = 1
End If

End Function

Public Function UnSetSystemWideKeyboardHook() As Long

' Unhook from the keyboard process

If m_hLLKeyboardHook <> 0 Then
Call UnhookWindowsHookEx(m_hLLKeyboardHook)
m_hLLKeyboardHook = 0
UnSetSystemWideKeyboardHook = 1
Else
UnSetSystemWideKeyboardHook = 0
End If

End Function

'窗体
Option Explicit

Private Sub Form_Load()
Form1.Visible = False
Call SetSystemWideKeyboardHook

End Sub
ARTERIOSCLEROS
2008-08-06 · TA获得超过4183个赞
知道大有可为答主
回答量:1672
采纳率:0%
帮助的人:2413万
展开全部
建一个Timer1,代码如下。
===============
Private Sub Form_Load()
Hide
WindowState = vbMinimized
Timer1.Interval = 2000
End Sub

Private Sub Timer1_Timer()
SendKeys "%{TAB}"
End Sub
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
thindy
2008-08-06 · TA获得超过1991个赞
知道小有建树答主
回答量:1409
采纳率:0%
帮助的人:446万
展开全部
靠,用什么vb啊~~用按键精灵算了
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式