Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Caps lock on at windows start-up 2

Status
Not open for further replies.

lived

Programmer
Jun 6, 2000
39
CA
i was wondering how i can manage to turn the caps lock on at windows start-up. i looked into the api viewer and did only find this:

Private Const CAPSLOCK_ON = &H80

someone have any ideas?

SkyFighter
skyfighta@hotmail.com
Get the fun out of life!

 
Hi,

This might not be the best way to do this but it will work (however it may need minor tweeking to suit your exact purpose).

Add the following code to a form and then create an .exe to open on startup.

Code:
Option Explicit

Private Declare Function GetKeyState Lib "user32" _
(ByVal nVirtKey As Long) As Integer

Private Declare Sub keybd_event Lib "user32" _
  (ByVal bVk As Byte, ByVal bScan As Byte, _
  ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Private Declare Function MapVirtualKey Lib "user32" _
Alias "MapVirtualKeyA" _
(ByVal wCode As Long, ByVal wMapType As Long) As Long

Private Const KEYEVENTF_EXTENDEDKEY = &H1
Private Const KEYEVENTF_KEYUP = &H2

Private Sub SetKeyState(ByVal Key As Long, ByVal State As Boolean)

  Call keybd_event(Key, MapVirtualKey(Key, 0), _
     KEYEVENTF_EXTENDEDKEY Or 0, 0)

    Call keybd_event(Key, MapVirtualKey(Key, 0), _
     KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0)

End Sub

Private Property Get CapsLock() As Boolean

  CapsLock = GetKeyState(KeyCodeConstants.vbKeyCapital) = 1

End Property

Private Property Let CapsLock(ByVal Value As Boolean)

  Call SetKeyState(KeyCodeConstants.vbKeyCapital, Value)

End Property

Private Sub Form_Load()
CapsLock = Not CapsLock
Unload Me
End Sub

What the above code does is toggle the CAPSLOCK key from it's current state. Assuming the user doesn't press the key before the program loads it should be fine. However it wouldn't take much modification to check the current state of the key...

Out of interest why do you wish to do this???

Cheers

Harleyquinn

---------------------------------
For tsunami relief donations
 
There's a registry setting for this, you know...

Saves on all that nasty programming effort

Start Regedit

Go to HKEY_CURRENT_USER\Control Panel\Keyboard \InitialKeyboardIndicators
Change the value to one of the following numbers
0 - All Keys off
1 - Caps Lock on
2 - Num Lock on
4 - Scroll Lock on
For multiple keys, add their values:
3 - Caps Lock and Num Lock on
5 - Caps Lock and Scroll Lock on
6 - Num Lock and Scroll Lock on
7 - Caps Lock, Num Lock, and Scroll Lock on
Log off and back on again
 
thank you both, especially strongm this is really helpful!

SkyFighter
skyfighta@hotmail.com
Get the fun out of life!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top