Hjæælp
Er der nogen der kan finde fejlen i dette program?Form11 kode:
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Const MOUSEEVENTF_LEFTDOWN = &H2
Const MOUSEEVENTF_LEFTUP = &H4
Const MOUSEEVENTF_MIDDLEDOWN = &H20
Const MOUSEEVENTF_MIDDLEUP = &H40
Const MOUSEEVENTF_MOVE = &H1
Const MOUSEEVENTF_ABSOLUTE = &H8000
Const MOUSEEVENTF_RIGHTDOWN = &H8
Const MOUSEEVENTF_RIGHTUP = &H10
Option Explicit
Dim retVal0 As Boolean, retVal1 As Boolean, retVal2 As Boolean
Private Sub Form_Load()
MsgBox "Brug genvej CTRL+F1 = Start, CTRL+F2 = Stop, CTRL+F3 = Luk"
retVal0 = RegisterHotKey(Me.hwnd, 0, MOD_CTRL, VK_F1)
If Not retVal0 Then
MsgBox "Kan ikke bruge denne genvej CTRL+F1 da den bliver brugt af et andet program.", vbCritical
End If
retVal1 = RegisterHotKey(Me.hwnd, 1, MOD_CTRL, VK_F2)
If Not retVal1 Then
MsgBox "Kan ikke bruge denne genvej CTRL+F2 da den bliver brugt af et andet program.", vbCritical
End If
retVal2 = RegisterHotKey(Me.hwnd, 2, MOD_CTRL, VK_F3)
If Not retVal2 Then
MsgBox "Kan ikke bruge denne genvej CTRL+F3 da den bliver brugt af et andet program.", vbCritical
End If
If (retVal0 = False And retVal1 = False And retVal2 = False) Then
MsgBox "Ingen genveje blev brugt!", vbCritical
End
End If
' Subclassing the form to get the Windows callback msgs.
glWinRet = SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOf CallbackMsgs)
End Sub
Private Sub Form_Resize()
If Me.WindowState = 1 Then
Me.Hide
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
' If first hotkey is registered then
' unregister it.
If retVal0 Then
UnregisterHotKey Me.hwnd, 0
End If
' If second hotkey is registered then
' unregister it.
If retVal1 Then
UnregisterHotKey Me.hwnd, 1
End If
' If third hotkey is registered then
' unregister it.
If retVal2 Then
UnregisterHotKey Me.hwnd, 2
End If
End Sub
Private Sub box1_Click()
If box1.Value = 1 Then
Timer1.Interval = 1000
End If
If box1.Value = 1 Then
box2.Value = 0
End If
If box1.Value = 1 Then
box3.Value = 0
End If
End Sub
Private Sub box2_Click()
If box2.Value = 1 Then
Timer1.Interval = 500
End If
If box2.Value = 1 Then
box1.Value = 0
End If
If box2.Value = 1 Then
box3.Value = 0
End If
End Sub
Private Sub box3_Click()
If box3.Value = 1 Then
Timer1.Interval = 250
End If
If box3.Value = 1 Then
box2.Value = 0
End If
If box3.Value = 1 Then
box1.Value = 0
End If
End Sub
Private Sub Luk_Click()
End
End Sub
Private Sub Start_Click()
Timer1.Enabled = True
End Sub
Private Sub Stop_Click()
Timer1.Interval = 0
End Sub
Private Sub Timer1_Timer()
'Simulate a mouseclick on the cursor's position
mouse_event MOUSEEVENTF_LEFTDOWN Or MOUSEEVENTF_LEFTUP, 0&, 0&, cButt, dwEI
DoEvents
Timer1.Enabled = False
Call Start_Click
End Sub
Module1 kode:
Option Explicit
Public Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As Long, _
ByVal ID As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long
Public Declare Function UnregisterHotKey Lib "user32" (ByVal hwnd As Long, _
ByVal ID As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" _
(ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Const WM_HOTKEY = &H312
Public Const GWL_WNDPROC = -4
Public Const MOD_CTRL = &H2 'This example uses CTRL
Public Const MOD_SHFT = &H4
Public Const MOD_ALT = &H1
' VK_A thru VK_Z are the same as their ASCII equivalents: 'A' thru 'Z'
' VK_0 thru VK_9 are the same as their ASCII equivalents: '0' thru '9'
' and others are listed below
Public Const VK_NUMPAD0 = &H60
Public Const VK_NUMPAD1 = &H61
Public Const VK_NUMPAD2 = &H62
Public Const VK_NUMPAD3 = &H63
Public Const VK_NUMPAD4 = &H64
Public Const VK_NUMPAD5 = &H65
Public Const VK_NUMPAD6 = &H66
Public Const VK_NUMPAD7 = &H67
Public Const VK_NUMPAD8 = &H68
Public Const VK_NUMPAD9 = &H69
Public Const VK_MULTIPLY = &H6A
Public Const VK_ADD = &H6B
Public Const VK_SEPARATOR = &H6C
Public Const VK_SUBTRACT = &H6D
Public Const VK_DECIMAL = &H6E
Public Const VK_DIVIDE = &H6F
Public Const VK_F1 = &H70
Public Const VK_F2 = &H71
Public Const VK_F3 = &H72
Public Const VK_F4 = &H73
Public Const VK_F5 = &H74
Public Const VK_F6 = &H75
Public Const VK_F7 = &H76
Public Const VK_F8 = &H77
Public Const VK_F9 = &H78
Public Const VK_F10 = &H79 ' This example uses F10
Public Const VK_F11 = &H7A ' This example uses F11
Public Const VK_F12 = &H7B ' This example uses F12
Public Const VK_F13 = &H7C
Public Const VK_F14 = &H7D
Public Const VK_F15 = &H7E
Public Const VK_F16 = &H7F
Public Const VK_F17 = &H80
Public Const VK_F18 = &H81
Public Const VK_F19 = &H82
Public Const VK_F20 = &H83
Public Const VK_F21 = &H84
Public Const VK_F22 = &H85
Public Const VK_F23 = &H86
Public Const VK_F24 = &H87
Public glWinRet As Long
' Function : CallbackMsgs
' This functions is used as a parameter in the
' API SetWindowLong(), by AddresOf operator, so as to
' Subclass the form to get the Windows Callback msgs...
Public Function CallbackMsgs(ByVal wHwnd As Long, ByVal wmsg As Long, ByVal wp_id As Long, ByVal lp_id As Long) As Long
If wmsg = WM_HOTKEY Then
Call DoFunctions(wp_id)
CallbackMsgs = 1
Exit Function
End If
CallbackMsgs = CallWindowProc(glWinRet, wHwnd, wmsg, wp_id, lp_id)
End Function
' Sub : DoFunction
' Activated by the Function "CallbackMsgs()" whenever
' a hotkey is pressed.
Public Sub DoFunctions(ByVal vKeyID As Byte)
' Important Notes :
' Do not include any msgboxes or Modal forms in
' this procedure, else if you include then by
' pressing the Hotkey twice/thrice the application
' will be terminated abnormally.
'
' But if it is a requirement for you to include the
' Modal forms or msgbox in this procedure then put
' the RegisterHotKey() API before hiding the Form
' and put the UnRegisterHotKey() API before Showing
' the form.
Form11.Show
Form11.WindowState = 0
DoEvents
' When the Hotkey is pressed once
' check if the Dofunctions() has completed
' before the CallbackMsgs().
' This check is not required if the form is
' minimized in the SysTray ...
If Form11.Visible = False Then
Form11.Show
Form11.WindowState = 0
End If
Form11.Cls
If vKeyID = 0 Then
Form11.Timer1.Enabled = True
Else
If vKeyID = 1 Then
Form11.Timer1.Interval = 0
Else
End
End If
End If
End Sub
Det bliver ved at medle om en fejl når man trykker på start. Fejlen kommer i cButt!
T2C
