2008-09-12 7 views

답변

12

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.iskeylocked.aspx

Imports System 
Imports System.Windows.Forms 
Imports Microsoft.VisualBasic 

Public Class CapsLockIndicator 

    Public Shared Sub Main() 
     if Control.IsKeyLocked(Keys.CapsLock) Then 
      MessageBox.Show("The Caps Lock key is ON.") 
     Else 
      MessageBox.Show("The Caps Lock key is OFF.") 
     End If 
    End Sub 'Main 
End Class 'CapsLockIndicator 



using System; 
using System.Windows.Forms; 

public class CapsLockIndicator 
{ 
    public static void Main() 
    { 
     if (Control.IsKeyLocked(Keys.CapsLock)) { 
      MessageBox.Show("The Caps Lock key is ON."); 
     } 
     else { 
      MessageBox.Show("The Caps Lock key is OFF."); 
     } 
    } 
} 
2

그렇게 만 PInvoke를 내 마음에 오는 :

Declare Function GetKeyState Lib "user32" 
    Alias "GetKeyState" (ByValnVirtKey As Int32) As Int16 

Private Const VK_CAPSLOCK = &H14 

If GetKeyState(VK_CAPSLOCK) = 1 Then ... 
1

5 밀리 초로 설정되고 활성화되어 타이머를 만듭니다. 그런 다음 label1이라는 레이블을 만듭니다. 그 후에 다음 코드를 (타이머에서) 시도하십시오. .rp에 의해 게시

Public Class Form1 

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick 
     If My.Computer.Keyboard.CapsLock = True Then 
      Label1.Text = "Caps Lock Enabled" 
     Else 
      Label1.Text = "Caps Lock Disabled" 
     End If 
    End Sub 
End Class 
0

이 솔루션은 작동하지만 Me.KeyDown 이벤트 핸들러와 충돌합니다. 입력을 누르면 로그인 기능을 호출하는 하위 항목이 있습니다. (아래 그림 참조) My.Computer.Keyboard.CapsLock 상태는 작동하며 Me.Keydown과 충돌하지 않습니다.

Private Sub WindowLogin_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown 

    If Keyboard.IsKeyDown(Key.Enter) Then 
     Call SignIn() 
    End If 

    End Sub 
관련 문제