Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Lock keyboard and mouse

Status
Not open for further replies.

jancheta

Programmer
Aug 30, 2002
51
US
Hi. I have a requirement where the keyboard and mouse needs to be locked. I don't know if access (any version) is capable of doing this.

Thanks in advance!

Jason
 
Hi, thanks for your input. I need to programmatically run processes on a users desktop but I don't want the user to be able to do anything on their computer, kinda like a screen saver (or maybe a screen saver can be called by access... but I guess that would be another hurdle communication between access and the screen saver)

You know, how the user presses [CTRL]+[ALT]+[DEL], then terminates Access.

I've come across various VB API sample codes (like below). Then I created a form, placed a timer event, but it wouldn't work.

--------
MODULE
--------
Option Compare Database
Public Declare Function GetCurrentThreadId Lib "kernel32" () As Long
Public Const WH_KEYBOARD = 2
Public Const VK_SHIFT = &H10
Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
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
Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public hHook As Long
Public Function KeyboardProc(ByVal idHook As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'if idHook is less than zero, no further processing is required
If idHook < 0 Then
'call the next hook
KeyboardProc = CallNextHookEx(hHook, idHook, wParam, ByVal lParam)
Else
'check if SHIFT-S is pressed
If (GetKeyState(VK_SHIFT) And &HF0000000) And wParam = Asc(&quot;S&quot;) Then
'show the result
MsgBox &quot;Shift-S pressed ...&quot;
End If
'call the next hook
KeyboardProc = CallNextHookEx(hHook, idHook, wParam, ByVal lParam)
End If
End Function

---------------
CODE for Form1
---------------
Option Compare Database
Dim abc As Long
Private Sub Form_Open(Cancel As Integer)
abc = 1
hHook = SetWindowsHookEx(WH_KEYBOARD, AddressOf KeyboardProc, 0, GetCurrentThreadId)
' hHook = SetWindowsHookEx(WH_KEYBOARD, AddressOf KeyboardProc, App.hInstance, App.ThreadID)
End Sub

Private Sub Form_Timer()
abc = abc + 1
If abc = 6 Then
DoCmd.Close acForm, Me.Name
End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
UnhookWindowsHookEx hHook
End Sub
 
Apparently you're already using API calls. If that doesn't scare you, I recommend you crosspost this into the Visual Basic 5 & 6 forum, asking the same question. Access in itself does not have the functionality.


Personally though, you're going to have to trust your users somewhat. I'd put a STRONG warning against closing the computer while this process is running--then maybe a popup saying &quot;the process is complete, you may continue now&quot;.


Not perfect, but annoying: maybe you could open a &quot;PROCESS IS RUNNING&quot; form in &quot;dialog mode&quot;, which has a timer event that grabs the focus every 100ms or so. You see what I'm saying--if the user click somewhere else, the form grabs the focus right back. That is what I would recommend.

--
Find common answers using Google Groups:

Corrupt MDBs FAQ
 
Hi, thanks for the advise, I'll check out the VB forum. I know, some users just drive us bananas!

Hmm come to think of it, maybe this code will work on VB 6? If it does, then I can call the VB app from Access. The VB app will constantly check for a file on the directory as a flag, and if the file exists (or something to that effect), then the VB app will terminate.

Ahh, before the VB app runs, I should check if the flag file exists (just in case they pressed the power off switch).

Regards,

Jason
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top