Solved

disable the keyboard

Posted on 1998-11-18
11
503 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
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
 

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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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 50 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

743 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

10 Experts available now in Live!

Get 1:1 Help Now