Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Lock Keyboard and Mouse

Posted on 2006-06-16
6
Medium Priority
?
1,323 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 1200 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Loops Section Overview

610 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