Click here to Skip to main content
15,441,757 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi all

i want to make code for programaticaly Caps Lock On...

i create s code in 2005 Like...



But it's not Working....
Pelase Help Me......... :(( :((
Updated 10-Feb-18 5:13am
Member 7821471 7-Apr-11 13:01pm     CRLF
I'm so sorry i don't have my code on me, here this will help. You have to use the GetKeyState function and import the: Public Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Int32) As UShort. MSDN library Examples

Interesting, it is documented as working with VB.NET, but it doesn't. I tried it to, the OP is right, it does not work.
Share this answer
Which operating system are you using?

I found this note on msdn -

"The SendKeys class has been updated for the .NET Framework 3.0 to enable its use in applications that run on Windows Vista. The enhanced security of Windows Vista (known as User Account Control or UAC) prevents the previous implementation from working as expected.

The SendKeys class is susceptible to timing issues, which some developers have had to work around. The updated implementation is still susceptible to timing issues, but is slightly faster and may require changes to the workarounds. The SendKeys class tries to use the previous implementation first, and if that fails, uses the new implementation. As a result, the SendKeys class may behave differently on different operating systems. Additionally, when the SendKeys class uses the new implementation, the SendWait method will not wait for messages to be processed when they are sent to another process."

And this -

"in a form called Form1 containing a button called Button1. The button's tab index property should be set to 0. When the sample is running, double-click the form to trigger the button's click event using SendKeys.Send."

Maybe these two notes can act as pointers to you.
Share this answer
Imports System.Runtime.InteropServices

<DllImport("user32.dll", CallingConvention:=CallingConvention.StdCall, CharSet:=CharSet.Unicode, EntryPoint:="keybd_event", ExactSpelling:=True, SetLastError:=True)> _
    Private Shared Function keybd_event(ByVal bVk As Int32, ByVal bScan As Int32, _
               ByVal dwFlags As Int32, ByVal dwExtraInfo As Int32) As Boolean
    End Function

    <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Unicode)> _
    Private Shared Function GetKeyState(ByVal nVirtKey As Integer) As Short
    End Function

    Private Sub SetCapsLockKey(ByVal newState As Boolean)
        ' if the current state must be changed
        If CBool(GetKeyState(Keys.CapsLock)) <> newState Then
            ' programmatically press and release the CapsLock key
            keybd_event(Keys.CapsLock, 0, 0, 0)
            keybd_event(Keys.CapsLock, 0, &H2, 0)
        End If
    End Sub
Share this answer
VB6 contained many ugly things that were removed in VB.NET. Every bit of documentation I can find on using this to control the caps lock, is for VB6, or VBScript. It doesn't seem to be supported in VB.NET.
Share this answer
This method is documented in MSDN I dont usually program with VB.Net but do tell if it works
Share this answer
Dim ProcID As Integer
ProcID = Shell("Notepad.exe", AppWinStyle.NormalFocus)

When I ran that, the "hello" was typed into Notepad in uppercase. Perhaps CAPSLOCK is only on during that SendKeys and then gets turned off at the end of the function call?
Share this answer
LucaDN 2-Mar-11 17:15pm     CRLF
The solution I posted is written for and it works. The strange thing is that you must always send the lowercase version of the character! SendKeys.Send(mytext.ToLower) If CapsLock is active, the focused control will receive the uppercase version of the char, even if the lowercase version was sent. Strange ... but works.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900