Results 1 to 2 of 2

Thread: Pressing combinaton of Keys

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2009
    Posts
    16

    Pressing combinaton of Keys

    i want to press Shif+Ctr+1 at got focus of any textbox

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Pressing combinaton of Keys

    Do you mean you want to trap the Ctl+Shift+1 key in textbox ?

    If yes, then try this...

    Code:
    Option Explicit
    
    Private Declare Function GetKeyboardState _
    Lib "user32" (pbKeyState As Byte) As Long
    
    Private Declare Function GetAsyncKeyState _
    Lib "user32" (ByVal vKey As Long) As Integer
    
    Private Const VK_TAB = &H9
    Private Const VK_SHIFT = &H10
    Private Const VK_LBUTTON = &H1
    
    Private Myarray(255) As Byte
    Dim CtrlKey As Boolean, ShiftKey As Boolean
    
    Private Function Shifted(Optional RefreshState As Boolean = False) As Boolean
       Call RefreshKeyState(RefreshState)
       If ((Myarray(VK_SHIFT) And &H80) = &H80) Then
          Shifted = True
       End If
    End Function
    
    Private Sub RefreshKeyState(RefreshState As Boolean)
       If RefreshState Then
          Call GetKeyboardState(Myarray(0))
       End If
    End Sub
    Private Sub ShowKey()
        Dim BoolShift As Boolean, BoolCtl As Boolean
        Dim sMessage As String
    
        BoolShift = Shifted(False)
            
        '~~> Ctrl key pressed
        If GetAsyncKeyState(vbKeyControl) And &H8000 Then
            '~~> Ctrl+SHIFT pressed
            If GetAsyncKeyState(vbKeyShift) And &H8000 Then
                '~~> Ctrl+SHIFT+1 pressed
                If GetAsyncKeyState(vbKey1) And &H8000 Then
                    MsgBox "You pressed CTL+SHIF+1"
                    CtrlKey = False
                    Exit Sub
                End If
            End If
            
        End If
    End Sub
    
    Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
        Call ShowKey
    End Sub
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width