Solved

Lock Keyboard and Mouse

Posted on 2006-06-16
6
1,320 Views
Last Modified: 2008-01-09
I just want to lock keyboard and mouse via network..

Just like Internet Cafe Applications..

Thanks..
0
Comment
Question by:el_hey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
6 Comments
 
LVL 2

Expert Comment

by:cmjwebservices
ID: 16925717
An adaptation taken from http://www.codeproject.com/vb/net/LockKeyboard.asp.  Add the following class to your form:

Public Class clsLockKeyboard

    ' This is the function used in order to block the keyboard and mouse:
    Declare Function BlockInput Lib "User32" _
           (ByVal fBlockIt As Boolean) As Boolean
    ' This function will block the keyboard and mouse until a window with
    ' the specify caption will appear or the given time in seconds has
    ' past ( 0 seconds - wait forever).
    ' If the window with the caption appears than the given key is send
    ' to it and the input block is removed.
    Public Shared Function Wait2Send(ByVal caption As String, _
              ByVal keys As String, ByVal seconds As Integer)

        ' Indicates if the window with the given caption was found
        Dim success As Boolean = False

        ' Start time of the function
        Dim now As DateTime = DateTime.Now

        ' Begining of keyboard and mouse block
        BlockInput(True)

        While (success = False And (DateTime.Now.Subtract(now).Seconds _
                                               < seconds Or seconds = 0))
            Try
                ' Activating the window with desired function
                ' if the window is not found an exception is thrown.
                AppActivate(caption)

                ' Sending desired key stroke to the application window
                SendKeys.SendWait(keys)

                ' Indicates the window was found and keys sent
                success = True

            Catch
                ' Assuming window was not found and sleep for 100 miliseconds
                System.Threading.Thread.Sleep(100)
            End Try
        End While
        ' Release the keyboard block
        BlockInput(False)

    End Function

End Class
0
 
LVL 2

Expert Comment

by:cmjwebservices
ID: 16925730
Then add the following form to implement the above (a simple test):

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Imports ProgressForm.clsLockKeyboard
Imports System.Threading

Public Class frmLockKeyboard
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents btnLock As System.Windows.Forms.Button
    Friend WithEvents txtTest As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.btnLock = New System.Windows.Forms.Button
        Me.txtTest = New System.Windows.Forms.TextBox
        Me.SuspendLayout()
        '
        'btnLock
        '
        Me.btnLock.Location = New System.Drawing.Point(104, 8)
        Me.btnLock.Name = "btnLock"
        Me.btnLock.TabIndex = 0
        Me.btnLock.Text = "Lock"
        '
        'txtTest
        '
        Me.txtTest.Location = New System.Drawing.Point(8, 48)
        Me.txtTest.Name = "txtTest"
        Me.txtTest.Size = New System.Drawing.Size(272, 20)
        Me.txtTest.TabIndex = 1
        Me.txtTest.Text = "Click 'Lock' and try to type here ;)"
        '
        'frmLockKeyboard
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 78)
        Me.Controls.Add(Me.txtTest)
        Me.Controls.Add(Me.btnLock)
        Me.Name = "frmLockKeyboard"
        Me.Text = "frmLockKeyboard"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub btnLock_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLock.Click
        ProgressForm.clsLockKeyboard.BlockInput(True)
        System.Threading.Thread.Sleep(8000)
        ProgressForm.clsLockKeyboard.BlockInput(False)
        Me.txtTest.Text = "Keyboard and mouse unlocked."
    End Sub

End Class

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Good luck!
0
 
LVL 1

Author Comment

by:el_hey
ID: 16948632
I have tested your codes and found out that it can be break by a ctrl-alt-delete function.
0
 
LVL 2

Accepted Solution

by:
cmjwebservices earned 300 total points
ID: 16950794
Ctrl-Alt-Del is a SAS (Secure Attention Sequence) and cannot be disabled without writing a GINA DLL.  If you know C++ then this can be done.  Otherwise, there is no way to use a keyboard hook and trap Ctrl-Alt-Del...
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question