|
-
Feb 9th, 2006, 06:22 PM
#1
Thread Starter
Lively Member
caps lock
Hi,
How to enable caps locks in my app. so that caps is always on in my app. and that the user cannot turn it off.
-
Feb 9th, 2006, 06:38 PM
#2
Re: caps lock
Turn On Caps Lock : http://support.microsoft.com/?id=177674
User cannot turn it off : Don't know. Here is an alternative,
set the form's KeyPreview = True at design time.
Then in the form's Form_KeyDown event turn on the Caps Lock.
-
Feb 9th, 2006, 06:49 PM
#3
Hyperactive Member
Re: caps lock
 Originally Posted by greenba
Hi,
How to enable caps locks in my app. so that caps is always on in my app. and that the user cannot turn it off.
WHY WOULD YOU WANT TO DO THAT?
"I like to run on treadmills, because at least I know I'm getting nowhere."
- Me
-
Feb 9th, 2006, 07:08 PM
#4
Hyperactive Member
Re: caps lock
It can be done like this
VB Code:
Const VK_CAPITAL = &H14
Const VK_NUMLOCK = &H90
Const VK_SCROLL = &H91
Private Type KeyboardBytes
kbByte(0 To 255) As Byte
End Type
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Private Declare Function SetKeyboardState Lib "user32" (kbArray As KeyboardBytes) As Long
Dim kbArray As KeyboardBytes
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyCapital Then
TurnOn VK_CAPITAL
End If
End Sub
Private Sub Form_Load()
TurnOn VK_CAPITAL
End Sub
Private Sub TurnOn(vkKey As Long)
'Change a key
kbArray.kbByte(vkKey) = 1
'Set the keyboard state
SetKeyboardState kbArray
End Sub
To deny our own impulses is to deny the very thing that makes us human
-
Feb 9th, 2006, 10:47 PM
#5
Re: caps lock
@guyvdn
The problem with SetKeyboardState is, it will set the Caps Lock state correctly, but it will not turn on keyboard LED on Win2000/XP systems. It may confuse the user.
On Win200/XP systems, we need to simulate a keypress using keybd_event.
Last edited by iPrank; Feb 9th, 2006 at 10:52 PM.
-
Feb 10th, 2006, 12:31 AM
#6
Frenzied Member
Re: caps lock
is there really a need for you to have the caps lock always on. if its just for a few textboxes, used the keypress event of the textbox
VB Code:
private sub text1_keypress(keyascii as integer)
keyascii = asc(ucase(chr(keyascii)))
end sub
On error goto Trap
Trap:
in case of emergency, drop the case...
****************************************
If this post has been resolved. Please mark it as "Resolved" by going through the "Thread Tools" above and clicking on the "Mark Thread Resolved " option. if a post is helpful to you, Please Rate it by clicking on the Rate link right below the avatar
-
Feb 10th, 2006, 02:38 AM
#7
Hyperactive Member
Re: caps lock
 Originally Posted by iPrank
@guyvdn
The problem with SetKeyboardState is, it will set the Caps Lock state correctly, but it will not turn on keyboard LED on Win2000/XP systems. It may confuse the user.
I didn’t notice that, I have a wireless keyboard and the leds are on a docking station that’s urm somewhere on my desk 
 Originally Posted by d3gerald
is there really a need for you to have the caps lock always on. if its just for a few textboxes, used the keypress event of the textbox
If you set keypreview of the form to true you can use the keypress event of the form. You only have to write the code once and it will work for all the controls. But the keyboard LED will also not be turned on.
To deny our own impulses is to deny the very thing that makes us human
-
Feb 10th, 2006, 02:43 AM
#8
Re: caps lock
PS2 or USB keyboard ? Mine is a plain PS2.
May be other members can give more different 'input'.
-
Feb 10th, 2006, 03:21 AM
#9
Re: caps lock
 Originally Posted by greenba
Hi,
How to enable caps locks in my app. so that caps is always on in my app. and that the user cannot turn it off.
I wouldn't do this. I wouldn't want Users to get annoyed when they CAPS lock turned on even when they didn't do anything. If you actually need UpperCase characters in your application, then you can always use UCase$ to convert the text in UpperCase. But doing unexpected is not what Users like.
Use [code] source code here[/code] tags when you post source code.
My Articles
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|