用VB编写按键程序
用VB编写模仿按键Alt+Tab的程序,要过程要使Form窗口隐藏,把WindowState设为1-Minimized...
用VB编写模仿按键Alt+Tab的程序,要过程
要使Form窗口隐藏,把WindowState设为1 - Minimized 展开
要使Form窗口隐藏,把WindowState设为1 - Minimized 展开
展开全部
'模块
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
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
展开全部
建一个Timer1,代码如下。
===============
Private Sub Form_Load()
Hide
WindowState = vbMinimized
Timer1.Interval = 2000
End Sub
Private Sub Timer1_Timer()
SendKeys "%{TAB}"
End Sub
===============
Private Sub Form_Load()
Hide
WindowState = vbMinimized
Timer1.Interval = 2000
End Sub
Private Sub Timer1_Timer()
SendKeys "%{TAB}"
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
靠,用什么vb啊~~用按键精灵算了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询