Solved

When outside the form or...

Posted on 1998-08-18
6
151 Views
Last Modified: 2011-04-14
formIs there a way for me to disable the keyboard if focus is outside of my form or even outside of a textbox?
0
Comment
Question by:JoKeRxSB
  • 3
  • 2
6 Comments
 
LVL 4

Expert Comment

by:Chizl
ID: 1429630
Give me an example on why you want to do this so I can figure out a solution.   I don't think disabling the keyboard is the right solution.
0
 

Author Comment

by:JoKeRxSB
ID: 1429631
I know that you cannot set a system modal so I was wondering if I could disable the keyboard.
0
 
LVL 4

Expert Comment

by:Chizl
ID: 1429632
There isn't an application on the market that disables the keyboard, because there is never a good reason to do so.  This is not good development planning if you need to cut the user out of using his/her keyboard.   Thank about that please before sending out an application that does such.
0
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

 
LVL 3

Accepted Solution

by:
a111a111a111 earned 100 total points
ID: 1429633
Hi, Here is a code that you can place within your code.

remember it is not advised to disable the keyboard so make your work after
you think its OKAY..

If you rename the keyboard.drv and no keyboard works at all you can rename it from DOS.


-------------- code start here -------------

Option Explicit
'When outside the form or...
Private Declare Function GetActiveWindow Lib "user32" () As Long

Private Type tagRect
   lngLeft As Long
   lngTop As Long
   lngRight As Long
   lngBottom As Long
End Type

' Two different declarations for the same API function.
Private Declare Sub ClipCursor Lib "user32" _
 (typRect As tagRect)
Private Declare Sub ClipCursorClear Lib "user32" _
 Alias "ClipCursor" (ByVal param As Any)

Private Declare Sub GetWindowRect Lib "user32" _
 (ByVal hWnd As Long, typRect As tagRect)

Private Sub cmdClip_Click()
   Dim typRect As tagRect
   Static sstrCaption As String
   Dim hWnd As Long
   Dim X
   Dim OldName
   Dim NewName
   Dim MyFile
   Static fClip As Boolean
   On Error Resume Next
   OldName = "c:\101.txt" 'you can play with renaming the file "Keyboard.drv" I did not try it
   NewName = "c:\111.txt" 'you can play with renaming the file "Keyboard.drv" I did not try it
     
   Name OldName As NewName ' Rename file.
           
   If fClip Then
      Call ClipCursorClear(vbNullString)
      cmdClip.Caption = sstrCaption
   Else
      hWnd = GetActiveWindow()
      sstrCaption = cmdClip.Caption
      cmdClip.Caption = "Free the Mouse!"
      Name NewName As OldName   ' Rename file.
      Call GetWindowRect(hWnd, typRect)
      Call ClipCursor(typRect)
     
   End If
   fClip = Not fClip
End Sub

Private Sub Form_Load()
   Call ClipCursorClear(vbNullString)
   KeyPreview = True
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    ' Just as a hint so may be you can do something with that!
    Select Case KeyCode
        Case vbKeyF1: MsgBox "F1 is your friend."
        Case vbKeyF2: MsgBox "F2 could copy text."
        Case vbKeyF3: MsgBox "F3 could paste text."
        Case vbKeyF4: MsgBox "F4 could format text."
    End Select
End Sub

-------- code end here ----------

shay@hili.com
0
 
LVL 4

Expert Comment

by:Chizl
ID: 1429634
OMG! Don't tell me your renaming the keyboard.drv.  

a111a111a111,
Looking at the questions you have answered a111a111a111 I see most of them are answered the same way and some are even answered with an answer that isn't an answer, but others for the same question were and your answer was excepted.  Seems to me your answering your own questions with you logging in as someone else.

If not then I suggest not telling people things that have an effect on their OS like this would.

0
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1429635
JoKeRxSB
Please take my answer off the EE.

I would never disable the keyboard on a PC system.

To all the users here:
I am sorry (what Bill never...) about the answer here.
Do not use my method to disable the keyboard.

The only time one would disable the keyboard is maybe on a network when a PC is a client and you do not like any one to touch the keyboard.

In that case lock the keyboard or just place it in a safe drawer.



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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

757 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

19 Experts available now in Live!

Get 1:1 Help Now