|
-
May 1st, 2008, 04:58 PM
#1
Thread Starter
Lively Member
Lock computer
I am making this small program to lock my computer if anybody "touches" it but I got stuck...
1. Double click on shortcut, program starts, label shows "Lock Enabled"
2. After a second, main form (mainly just the above label on it) hides -Timer1
3. If keypress other than "ctrl+S" / if either mouse button clicked - computer locks - Timer2
4. If "ctrl+S" pressed, label shows "Lock Disabled", program shuts down (for mr to quick disable it when I'm back on my desk) - Timer3
Now, I have problems with step 3 where I need to check if any key (except "ctrl + S") or mouse buttons are pressed, which I cannot seem to accomplish. Any help would be appreciated. Below is the code I have so far:
Code:
Option Explicit
Private Declare Function LockWorkStation Lib "user32.dll" () As Long
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As KeyCodeConstants) As Long
Public Function KeyDown(ByVal vKey As KeyCodeConstants) As Boolean
KeyDown = GetAsyncKeyState(vKey) And &H8000
End Function 'KeyDown(ByVal vKey As KeyCodeConstants) As Boolean
Private Sub StationLock()
LockWorkStation
End Sub 'Lock()
Private Sub tmrTimer1_Timer()
frmLock.Visible = False
tmrTimer.Enabled = False
End Sub 'tmrTimer_Timer()
Private Sub tmrTimer2_Timer()
If KeyDown(vbKeyControl) And KeyDown(vbKeyS) Then
lblInfo.Caption = "Lock Disabled"
lblInfo.ForeColor = &HC0&
frmLock.Visible = True
tmrTimer3.Enabled = True
Else
'----------this shows even if no key is pressed at all
MsgBox "Locked" 'StationLock
End If 'KeyDown(vbKeyControl) And KeyDown(vbKeyS)
End Sub 'tmrTimer2_Timer()
Private Sub tmrTimer3_Timer()
End
End Sub 'tmrTimer3_Timer()
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|