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

x
?
Solved

When outside the form or...

Posted on 1998-08-18
6
Medium Priority
?
219 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
[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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 3

Accepted Solution

by:
a111a111a111 earned 200 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

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!

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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 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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

721 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