Results 1 to 11 of 11

Thread: sendkeys question

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2002
    Posts
    39

    sendkeys question

    how do i send the enter key?

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    VB Code:
    1. SendKeys "{ENTER}"

  3. #3
    Hyperactive Member
    Join Date
    Mar 2002
    Posts
    424
    Just in case you missed the post in the other file. HOw do I determine left from right ctrl keys and the two enter keys?

  4. #4
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765
    If you've got MSDN, look up SendKeys, it has the list of Keys that you can use their.


    And.... I think the keyboard sees the 2 Ctrl Buttons as the same key, and won't know the difference between the 2.
    Don't Rate my posts.

  5. #5
    Let me in .. techyspecy's Avatar
    Join Date
    Aug 2002
    Location
    Back to VBF.
    Posts
    2,456
    If you want to differentiate between two control keys you are going to have to write a keyboard hook program and trap the scan codes of the keys. I believe scan code of both controls are different. You can get lot of such programs on www.pscode.com/vb

  6. #6
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765
    Well... I used a program which displays the values for the keys, and it returned 18 for both Alt Buttons...
    Don't Rate my posts.

  7. #7
    Hyperactive Member
    Join Date
    Mar 2002
    Posts
    424
    pc Madness: I have a couple of programs that have different functions for the two ctrl keys and alt keys. That program can tell which ctrl or alt key has been pressed. I gotta figure out how it does that. Same with the enter keys.

    techyspecy: Thanks, I'll check out those programs and let you know.

  8. #8
    Let me in .. techyspecy's Avatar
    Join Date
    Aug 2002
    Location
    Back to VBF.
    Posts
    2,456
    Originally posted by Ephesians
    pc Madness: I have a couple of programs that have different functions for the two ctrl keys and alt keys. That program can tell which ctrl or alt key has been pressed. I gotta figure out how it does that. Same with the enter keys.

    techyspecy: Thanks, I'll check out those programs and let you know.
    Here's how to do that.


    Place this code in standard module.

    Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)


    Public Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long

    Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long

    Public Const WH_KEYBOARD_LL = 13
    Public Const HC_ACTION = 0
    Public Const WM_KEYDOWN = &H100
    Public Const WM_KEYUP = &H101
    Public Const WM_SYSKEYDOWN = &H104
    Public Const WM_SYSKEYUP = &H105

    Public Function KeyboardHookProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

    If (nCode = HC_ACTION) Then
    If (wParam = WM_KEYDOWN Or wParam = WM_SYSKEYDOWN) Then

    CopyMemory k, ByVal lParam, Len(k)

    MsgBox k.vkCode

    endif
    endif
    KeyboardHookProc = CallNextHookEx(hHook, nCode,
    wParam, ByVal lParam)
    end function

    'instead of scan code, you look for Virtual key code. Vistual key
    'code for left ctrl is 162 while for right ctrl key its 163.


    place this in general declaration of form

    Dim hHook As Long

    Place this code in the command button click event on the form ...

    Private sub command1_click()
    hHook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf
    KeyboardHookProc, App.hInstance, 0)
    end sub

    Please add all constants and API's (if i am missing any) to the standard module .....

    This will do the stuff for you ..........
    Last edited by techyspecy; Nov 15th, 2002 at 09:13 AM.

  9. #9
    Hyperactive Member
    Join Date
    Mar 2002
    Posts
    424
    Now that's what I'm talking about.. Thanks a bunch!

  10. #10
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    You can also use GetAsyncKeyState()
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    4.  
    5. Private Const VK_CONTROL = &H11
    6. Private Const VK_LCONTROL = &HA2
    7. Private Const VK_RCONTROL = &HA3
    8.  
    9. Private Const VK_MENU = &H12
    10. Private Const VK_LMENU = &HA4
    11. Private Const VK_RMENU = &HA5
    12.  
    13. Private Const VK_SHIFT = &H10
    14. Private Const VK_LSHIFT = &HA0
    15. Private Const VK_RSHIFT = &HA1
    16.  
    17. Private Const VK_RETURN = &HD
    18.  
    19. Private Sub Form_Load()
    20.   Dim lKey As Long
    21.  
    22.   ' Wait for Keyboard Buffer to Clear
    23.   For lKey = 0 To 255
    24.     Do While GetAsyncKeyState(lKey) <> 0
    25.       DoEvents
    26.     Loop
    27.   Next
    28.  
    29.   ' Turn on Timer
    30.   Timer1.Interval = 100
    31. End Sub
    32.  
    33. Private Sub Timer1_Timer()
    34.   Dim lKey As Long
    35.  
    36.   ' Check all Key States
    37.   For lKey = 0 To 255
    38.     If GetAsyncKeyState(lKey) <> 0 Then
    39.       Select Case lKey
    40.       Case VK_CONTROL
    41.         Debug.Print "CONTROL"
    42.        
    43.       Case VK_MENU
    44.         Debug.Print "ALT"
    45.        
    46.       Case VK_SHIFT
    47.         Debug.Print "SHIFT"
    48.        
    49.       Case VK_LCONTROL
    50.         Debug.Print "LEFT CONTROL"
    51.        
    52.       Case VK_LMENU
    53.         Debug.Print "LEFT ALT"
    54.        
    55.       Case VK_LSHIFT
    56.         Debug.Print "LEFT SHIFT"
    57.        
    58.       Case VK_RCONTROL
    59.         Debug.Print "RIGHT CONTROL"
    60.        
    61.       Case VK_RMENU
    62.         Debug.Print "RIGHT ALT"
    63.        
    64.       Case VK_RSHIFT
    65.         Debug.Print "RIGHT SHIFT"
    66.        
    67.       Case VK_RETURN
    68.         Debug.Print "RETURN/ENTER"
    69.        
    70.       End Select
    71.     End If
    72.   Next
    73. End Sub

  11. #11
    Let me in .. techyspecy's Avatar
    Join Date
    Aug 2002
    Location
    Back to VBF.
    Posts
    2,456
    I am sorry ephseians, i missed a important part ...

    add this also to standard module .......

    Global hHook As Long

    Public Type KBDLLHOOKSTRUCT
    vkCode As Long
    scanCode As Long
    flags As Long
    time As Long
    dwExtraInfo As Long
    End Type

    Dim k As KBDLLHOOKSTRUCT

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