<p>How do I find out whether or not Caps Lock is activated, using VB.NET?</p>

<p>This is a follow-up to my <a href="https://stackoverflow.com/questions/58937/how-do-i-toggle-caps-lock-in-vbnet">earlier question</a>.</p>

[{'answer_id': 58991, 'author': 'aku', 'author_id': 1196, 'author_profile': 'https://Stackoverflow.com/users/1196', 'pm_score': 2, 'selected': False, 'text': '<p>I\'m not an expert in VB.NET so only PInvoke comes to my mind:</p>\n\n<pre><code>Declare Function GetKeyState Lib "user32" \n   Alias "GetKeyState" (ByValnVirtKey As Int32) As Int16\n\nPrivate Const VK_CAPSLOCK = &amp;H14\n\nIf GetKeyState(VK_CAPSLOCK) = 1 Then ...\n</code></pre>\n'}, {'answer_id': 58993, 'author': 'rp.', 'author_id': 2536, 'author_profile': 'https://Stackoverflow.com/users/2536', 'pm_score': 5, 'selected': True, 'text': '<p><a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.iskeylocked.aspx" rel="noreferrer">Control.IsKeyLocked(Keys) Method - MSDN</a></p>\n\n<pre><code>Imports System\nImports System.Windows.Forms\nImports Microsoft.VisualBasic\n\nPublic Class CapsLockIndicator\n\n    Public Shared Sub Main()\n        if Control.IsKeyLocked(Keys.CapsLock) Then\n            MessageBox.Show("The Caps Lock key is ON.")\n        Else\n            MessageBox.Show("The Caps Lock key is OFF.")\n        End If\n    End Sub \'Main\nEnd Class \'CapsLockIndicator\n</code></pre>\n\n<hr>\n\n<p>C# version:</p>\n\n<pre class="lang-cs prettyprint-override"><code>using System;\nusing System.Windows.Forms;\n\npublic class CapsLockIndicator\n{\n    public static void Main()\n    {\n        if (Control.IsKeyLocked(Keys.CapsLock)) {\n            MessageBox.Show("The Caps Lock key is ON.");\n        }\n        else {\n            MessageBox.Show("The Caps Lock key is OFF.");\n        }\n    }\n}\n</code></pre>\n'}, {'answer_id': 29317731, 'author': 'JumboUser155', 'author_id': 4401083, 'author_profile': 'https://Stackoverflow.com/users/4401083', 'pm_score': 2, 'selected': False, 'text': '<p>Create a Timer that is set to 5 milliseconds and is enabled.<br>\nThen make a label named <code>label1</code>. After, try the following code (in the timer event handler).</p>\n\n<pre><code>Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick\n    If My.Computer.Keyboard.CapsLock = True Then\n        Label1.Text = "Caps Lock Enabled"\n    Else\n        Label1.Text = "Caps Lock Disabled"\n    End If\nEnd Sub\n</code></pre>\n'}, {'answer_id': 43073619, 'author': 'Thomas Bailey', 'author_id': 6416987, 'author_profile': 'https://Stackoverflow.com/users/6416987', 'pm_score': 0, 'selected': False, 'text': '<p>The solution posted by <a href="https://stackoverflow.com/a/58993/7444103">.rp</a> works, but conflicts with the <code>Me.KeyDown</code> event handler.<br>\nI have a sub that calls a sign in function when enter is pressed (shown below).<br>\nThe <code>My.Computer.Keyboard.CapsLock</code> state works and does not conflict with <code>Me.Keydown</code>.</p>\n\n<pre><code>Private Sub WindowLogin_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown\n\n    If Keyboard.IsKeyDown(Key.Enter) Then\n        Call SignIn()\n    End If\n\nEnd Sub\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/58976', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/133/']