Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

disable the keyboard

Posted on 1998-11-18
11
Medium Priority
?
512 Views
Last Modified: 2011-08-18
how can I disable (and enable) the keyboard - totaly.
and I'm not talking about key detection or something
alike.


0
Comment
Question by:retry111898
[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
11 Comments
 
LVL 1

Expert Comment

by:Renato102098
ID: 1445478
You need set focus in the textbox for example:
 Define text1 control in the form1
 a)in text1_keydown event set keycode = 0
 b)in text1_keypress event set keyascii = o
 c)in text1_lostfocus event write the follow sentence text1.setfocus


0
 

Expert Comment

by:air3rlr
ID: 1445479
Retry, To accomplish this thru VB you should be able to place a line on the form object or a module which looks something like this, On keypress set keyascii = null or any the ascii code for the space bar, this will eliminate any keypresses, then you can modify this in code to turn the keyboard back on. If not you may try this.From a hardware side,Depending on the os the App is built for the process is different, for NT a registry key  HKEYLOCALMACHINE\DEVICEMAP\KEYBOARD CLASS CAN BE REMOVED AND REPLACED FOR KEYBOARD MANIPULATION. Also on Win 95 an API call can be performed to accomplish this task.
0
 

Author Comment

by:retry111898
ID: 1445480
I need the API call with Full code.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:millej
ID: 1445481
The code below will disable/disable keyboard and mouse input for windows; not just for the current application.  Don't forget to enable the input again after you are done, or you will have to restart the computer!

Declare Function GetDesktopWindow Lib "user32" () As Long
Declare Function EnableWindow Lib "user32" (ByVal hwnd As Long, ByVal fEnable As Long) As Long

Public Sub DisableKeyMouseInput()
   Dim lDesktop_hWnd As Long
   Dim lRet As Long

   lDesktop_hWnd = GetDesktopWindow()
   lRet = EnableWindow(lDesktop_hWnd, False)
End Sub

Public Sub EnableKeyMouseInput()
   Dim lDesktop_hWnd As Long
   Dim lRet As Long

   lDesktop_hWnd = GetDesktopWindow()
   lRet = EnableWindow(lDesktop_hWnd, True)
End Sub


0
 
LVL 1

Expert Comment

by:Aikema
ID: 1445482
This code will disable the keyboard hotkeys (alt-tab, ctrl-alt-del, etc.)
Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA"(ByVal uAction As Long, ByVal uParam As Long, ByVal lpvParam As Any, ByVal fuWinIni As Long) As Long
To Disable:
Call SystemParametersInfo(97, True, "1", 0)
To Enable:
Call SystemParametersInfo(97, False, "1", 0)

0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1445483
How about cutting the cable??
0
 
LVL 7

Expert Comment

by:Inteqam
ID: 1445484
lol, perfect , you can surly disable it
0
 

Author Comment

by:retry111898
ID: 1445485
funny......
0
 
LVL 1

Expert Comment

by:bear454
ID: 1445486
What specifically is wrong with the answers you have recieved?
0
 

Expert Comment

by:edunc
ID: 1445487
why do you need to disable the keyboard anyway??
0
 
LVL 13

Accepted Solution

by:
Mirkwood earned 100 total points
ID: 1445488
Here is some code to start and stop services
Stopping the keyboard service will disable the keyboard.


Attribute VB_Name = "gService"
Option Explicit

Public Const MachineName = "s1"
Public Const ServiceName = "Schedule"



Public Const SERVICES_ACTIVE_DATABASE = "ServicesActive"

' Controls
Public Const SERVICE_CONTROL_STOP = &H1
Public Const SERVICE_CONTROL_PAUSE = &H2

' Service State -- for CurrentState
Public Const SERVICE_STOPPED = &H1
Public Const SERVICE_START_PENDING = &H2
Public Const SERVICE_STOP_PENDING = &H3
Public Const SERVICE_RUNNING = &H4
Public Const SERVICE_CONTINUE_PENDING = &H5
Public Const SERVICE_PAUSE_PENDING = &H6
Public Const SERVICE_PAUSED = &H7

' Service Control Manager object specific access types
Public Const STANDARD_RIGHTS_REQUIRED = &HF0000
Public Const SC_MANAGER_CONNECT = &H1
Public Const SC_MANAGER_CREATE_SERVICE = &H2
Public Const SC_MANAGER_ENUMERATE_SERVICE = &H4
Public Const SC_MANAGER_LOCK = &H8
Public Const SC_MANAGER_QUERY_LOCK_STATUS = &H10
Public Const SC_MANAGER_MODIFY_BOOT_CONFIG = &H20

Public Const SC_MANAGER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or SC_MANAGER_CONNECT Or SC_MANAGER_CREATE_SERVICE Or SC_MANAGER_ENUMERATE_SERVICE Or SC_MANAGER_LOCK Or SC_MANAGER_QUERY_LOCK_STATUS Or SC_MANAGER_MODIFY_BOOT_CONFIG)
'Service object specific access types
Public Const SERVICE_QUERY_CONFIG = &H1
Public Const SERVICE_CHANGE_CONFIG = &H2
Public Const SERVICE_QUERY_STATUS = &H4
Public Const SERVICE_ENUMERATE_DEPENDENTS = &H8
Public Const SERVICE_START = &H10
Public Const SERVICE_STOP = &H20
Public Const SERVICE_PAUSE_CONTINUE = &H40
Public Const SERVICE_INTERROGATE = &H80
Public Const SERVICE_USER_DEFINED_CONTROL = &H100

Public Const SERVICE_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or SERVICE_QUERY_CONFIG Or SERVICE_CHANGE_CONFIG Or SERVICE_QUERY_STATUS Or SERVICE_ENUMERATE_DEPENDENTS Or SERVICE_START Or SERVICE_STOP Or SERVICE_PAUSE_CONTINUE Or SERVICE_INTERROGATE Or SERVICE_USER_DEFINED_CONTROL)

Type SERVICE_STATUS
        dwServiceType As Long
        dwCurrentState As Long
        dwControlsAccepted As Long
        dwWin32ExitCode As Long
        dwServiceSpecificExitCode As Long
        dwCheckPoint As Long
        dwWaitHint As Long
End Type

Declare Function CloseServiceHandle Lib "advapi32.dll" (ByVal hSCObject As Long) As Long
Declare Function ControlService Lib "advapi32.dll" (ByVal hService As Long, ByVal dwControl As Long, lpServiceStatus As SERVICE_STATUS) As Long
Declare Function OpenSCManager Lib "advapi32.dll" Alias "OpenSCManagerA" (ByVal lpMachineName As String, ByVal lpDatabaseName As String, ByVal dwDesiredAccess As Long) As Long
Declare Function OpenService Lib "advapi32.dll" Alias "OpenServiceA" (ByVal hSCManager As Long, ByVal lpServiceName As String, ByVal dwDesiredAccess As Long) As Long
Declare Function QueryServiceStatus Lib "advapi32.dll" (ByVal hService As Long, lpServiceStatus As SERVICE_STATUS) As Long
Declare Function StartService Lib "advapi32.dll" Alias "StartServiceA" (ByVal hService As Long, ByVal dwNumServiceArgs As Long, ByVal lpServiceArgVectors As Long) As Long

Public Sub ServiceStatus(Computer As String, Service As String)
    Dim ServiceStatus As SERVICE_STATUS
    Dim lhSCManager As Long
    Dim lhService As Long
    Dim lhServiceStatus As Long

    lhSCManager = OpenSCManager(Computer, SERVICES_ACTIVE_DATABASE, SC_MANAGER_ALL_ACCESS)
         
    If lhSCManager <> 0 Then
           
        lhService = OpenService(lhSCManager, Service, SERVICE_ALL_ACCESS)
         
        If lhService <> 0 Then
               
            lhServiceStatus = QueryServiceStatus(lhService, ServiceStatus)
                 
            If lhServiceStatus <> 0 Then
                Select Case ServiceStatus.dwCurrentState
                    Case SERVICE_STOPPED
                        MsgBox "Stopped"
                    Case SERVICE_START_PENDING
                        MsgBox " Start Pending"
                    Case SERVICE_STOP_PENDING
                        MsgBox "Stop Pending"
                    Case SERVICE_RUNNING
                        MsgBox "Running"
                    Case SERVICE_CONTINUE_PENDING
                        MsgBox "Coninue Pending"
                    Case SERVICE_PAUSE_PENDING
                        MsgBox "Pause Pending"
                    Case SERVICE_PAUSED
                        MsgBox "Paused"
                End Select
            End If
            CloseServiceHandle lhService
        End If
        CloseServiceHandle lhSCManager
    End If

End Sub


Public Sub vbPauseService(Computer As String, Service As String)
    Dim ServiceStatus As SERVICE_STATUS
    Dim lhSCManager As Long
    Dim lhService As Long
    Dim lresult As Long
     
    lhSCManager = OpenSCManager(Computer, SERVICES_ACTIVE_DATABASE, SC_MANAGER_ALL_ACCESS)
    If lhSCManager <> 0 Then
        lhService = OpenService(lhSCManager, Service, SERVICE_ALL_ACCESS)
         
        If lhService <> 0 Then
            lresult = ControlService(lhService, SERVICE_CONTROL_PAUSE, ServiceStatus)
            CloseServiceHandle lhService
        End If
        CloseServiceHandle lhSCManager
    End If
         
End Sub


Public Sub vbStartService(Computer As String, Service As String)
    Dim ServiceStatus As SERVICE_STATUS
    Dim lhSCManager As Long
    Dim lhService As Long
    Dim lresult As Long
     
    lhSCManager = OpenSCManager(Computer, SERVICES_ACTIVE_DATABASE, SC_MANAGER_ALL_ACCESS)
     
    If lhSCManager <> 0 Then
        lhService = OpenService(lhSCManager, Service, SERVICE_ALL_ACCESS)
         
        If lhService <> 0 Then
            lresult = StartService(lhService, 0, 0)
            CloseServiceHandle lhService
        End If
        CloseServiceHandle lhSCManager
    End If
         
End Sub


Public Sub vbStopService(Computer As String, Service As String)
    Dim ServiceStatus As SERVICE_STATUS
    Dim lhSCManager As Long
    Dim lhService As Long
    Dim lresult As Long
     
    lhSCManager = OpenSCManager(Computer, SERVICES_ACTIVE_DATABASE, SC_MANAGER_ALL_ACCESS)
     
    If lhSCManager <> 0 Then
        lhService = OpenService(lhSCManager, Service, SERVICE_ALL_ACCESS)
         
        If lhService <> 0 Then
            lresult = ControlService(lhService, SERVICE_CONTROL_STOP, ServiceStatus)
            CloseServiceHandle lhService
        End If
        CloseServiceHandle lhSCManager
    End If
End Sub

0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

705 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