Click to See Complete Forum and Search --> : Locking the Keyboard and Mouse :)


Leo Koach
January 11th, 2000, 07:58 PM
I had lots of questions about how to lock the keyboard and mouse while program is working.

here is a little gift from me to you.
But wait! it works only with Win 95/98 (I just realised that)

<module>
Type RECT
left As Integer
top As Integer
right As Integer
bottom As Integer
End Type

Type POINT
x As Long
y As Long
End Type
Declare Sub ClipCursor Lib "user32" (lpRect As Any)
Declare Sub OffsetRect Lib "user32" (lpRect As RECT, ByVal x As Long, ByVal y As Long)
Declare Sub GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT)
Declare Sub ClientToScreen Lib "user32" (ByVal hwnd As Long, lpPoint As POINT)

<Form>


Private Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, lpvParam As Any, ByVal fuWinIni As Long) As Long
Private Const SPI_SCREENSAVERRUNNING = 97

Dim locked As Integer
Public privatecode As String

Private Sub Command1_Click()
If locked = 1 Then
Call unloc
locked = 0
Else
Call Lockit
locked = 1
End If
End Sub

Private Sub Form_Load()
If App.PrevInstance = True Then ' Check if the application is running
End
End If
End Sub

Public Sub cClipCursor()
Dim client As RECT
Dim upperleft As POINT
If locked = 0 Then
GetClientRect Me.hwnd, client
upperleft.x = client.left
upperleft.y = client.top
ClientToScreen Me.hwnd, upperleft
OffsetRect client, upperleft.x, upperleft.y
ClipCursor client
Else
ClipCursor ByVal 0&
End If
End Sub

Private Sub unloc()
Call cClipCursor
Dim ret As Integer
Dim pOld As Boolean
ret = SystemParametersInfo(SPI_SCREENSAVERRUNNING, False, pOld, 0)
Command1.Caption = "lock"
End Sub

Public Sub Lockit()
Call cClipCursor
Command1.Caption = "Unlock"
Dim ret As Integer
Dim pOld As Boolean
ret = SystemParametersInfo(SPI_SCREENSAVERRUNNING, True, pOld, 0)
End Sub


If anybody has better ides, please let me know

www.openplace.com