Solved

Lock Keyboard and Mouse

Posted on 2006-06-16
6
1,314 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
  • 3
6 Comments
 
LVL 2

Expert Comment

by:cmjwebservices
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now