2008-09-12 18 views

cevap

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

böylece sadece PInvoke aklıma gelir:

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 milisaniye olarak ayarlanır ve etkindir bir zamanlayıcı oluşturun. Ardından label1 adlı bir etiket oluşturun. Ardından, aşağıdaki kodu (zamanlayıcıda) deneyin. .rp tarafından gönderildi

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

çözüm çalışır ancak Me.KeyDown olay işleyicisi ile çakışıyor. Enter'a basıldığında, bir işlev çağrısı yapan bir altım var. (aşağıda gösterilmiştir) My.Computer.Keyboard.CapsLock durumu çalışır ve Me.Keydown ile çakışmaz.

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 
İlgili konular