• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 229
  • Last Modified:

When outside the form or...

formIs there a way for me to disable the keyboard if focus is outside of my form or even outside of a textbox?
0
JoKeRxSB
Asked:
JoKeRxSB
  • 3
  • 2
1 Solution
 
ChizlCommented:
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
 
JoKeRxSBAuthor Commented:
I know that you cannot set a system modal so I was wondering if I could disable the keyboard.
0
 
ChizlCommented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
a111a111a111Commented:
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
 
ChizlCommented:
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
 
a111a111a111Commented:
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

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now