خاموش و روشن کردن Caps Lock در ویژوال بیسیک

Visual Basic 6

توسط elahe در 5 سال پیش
0 753 1 5 سال پیش
elahevbprogrammer
0

سلام عید همگی مبارک :smilingsmiley: چطور میتونم کلید CapsLock رو خاموش و روشن کنم در ویژوال بیسیک؟

0

Salam

Option Explicit

Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal uCode As Long, ByVal uMapType As Long) As Long
Private Declare Function SendInput Lib "user32" (ByVal nInputs As Long, pInputs As Any, ByVal cbSize As Long) As Long

Private Type KeyboardInput       '   typedef struct tagINPUT {
   dwType As Long                '     DWORD type;
   wVK As Integer                '     union {MOUSEINPUT mi;
   wScan As Integer              '            KEYBDINPUT ki;
   dwFlags As Long               '            HARDWAREINPUT hi;
   dwTime As Long                '     };
   dwExtraInfo As Long           '   }INPUT, *PINPUT;
   dwPadding As Currency         '
End Type

'SendInput constants
Private Const INPUT_KEYBOARD As Long = 1
Private Const KEYEVENTF_KEYUP As Long = 2

Private Const VK_CAPITAL = &H14

Function CapsLock() As Boolean
   ' Determine whether CAPSLOCK key is toggled on.
   CapsLock = CBool(GetKeyState(VK_CAPITAL) And 1)
End Function

Public Sub SetCapsLockState(bEnabled As Boolean)
    'CapsLock is already in desired state. Nothing to do.
    If CapsLock = bEnabled Then Exit Sub

    PressCapsLock
End Sub

Private Sub PressCapsLock()
    GenerateKeyboardEvent VK_CAPITAL, 0
    GenerateKeyboardEvent VK_CAPITAL, KEYEVENTF_KEYUP
End Sub

Private Sub GenerateKeyboardEvent(VirtualKey As Long, Flags As Long)
    Dim kevent As KeyboardInput

    With kevent
        .dwType = INPUT_KEYBOARD
        .wScan = MapVirtualKey(VirtualKey, 0)
        .wVK = VirtualKey
        .dwTime = 0
        .dwFlags = Flags
    End With
    SendInput 1, kevent, Len(kevent)
End Sub

Private Sub Command1_Click()
    SetCapsLockState True
End Sub

Private Sub Command2_Click()
    SetCapsLockState False
End Sub

خوش آمدید

برای طرح سوال، ایجاد بحث و فعالیت در سایت نیاز است ابتدا وارد حساب کاربری خود شوید. در صورتی که هنوز عضو سایت نیستید میتوانید در عرض تنها چند ثانیه ثبت نام کنید.

لطفا ابتدا لاگین کنید