Results 1 to 8 of 8

Thread: [RESOLVED] Help how to simulate sendkeys in Vista?

  1. #1

    Thread Starter
    Addicted Member coolwater's Avatar
    Join Date
    Dec 2004
    Location
    philippines
    Posts
    215

    Resolved [RESOLVED] Help how to simulate sendkeys in Vista?

    I've been using this code for ages in triggering TAB in VB6 using XP as my OS.

    sendkeys Code:
    1. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    2. If KeyCode = vbKeyReturn Then
    3.     SendKeys vbTab
    4. End If
    5. End Sub

    I'm using Vista Business now as my OS and I'm having error problems with the code above. Is there a way to to use the code above in vista? or can you suggest an API that I can use for vista? Any help is greatly appreciated.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Help how to simulate sendkeys in Vista?

    SendKeys isnt supported in Vista. You can use the SendMessage or PostMessage aPIs to replicate the message.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Addicted Member coolwater's Avatar
    Join Date
    Dec 2004
    Location
    philippines
    Posts
    215

    Re: Help how to simulate sendkeys in Vista?

    tnx for the reply. can you point me to a link for a sample code? tnx.

  4. #4
    Addicted Member
    Join Date
    Jul 2007
    Posts
    228

    Re: Help how to simulate sendkeys in Vista?

    You need to use the keybd API

    Code:
    'Declares to include
    Private Const VK_TAB = &H9 
             
    Private Declare Sub keybd_event Lib "user32" _
      (ByVal bVk As Byte, _
       ByVal bScan As Byte, _
       ByVal dwFlags As Long, _
       ByVal dwExtraInfo As Long) 
    
    'heres the command to call
      keybd_event VK_TAB, 0, 0, 0 'send a tab

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Help how to simulate sendkeys in Vista?

    keybd_event requires input focus same as sendkeys but for the most stable method, see the APIs listed at http://allapi.mentalis.org.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Help how to simulate sendkeys in Vista?

    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  7. #7
    Fanatic Member newprogram's Avatar
    Join Date
    Apr 2006
    Location
    in your basement
    Posts
    769

    Re: Help how to simulate sendkeys in Vista?

    thank you RobDog888 the api guild there is a big help
    Quote Originally Posted by RobDog888
    keybd_event requires input focus same as sendkeys but for the most stable method, see the APIs listed at http://allapi.mentalis.org.
    Live life to the fullest!!

  8. #8

    Thread Starter
    Addicted Member coolwater's Avatar
    Join Date
    Dec 2004
    Location
    philippines
    Posts
    215

    Re: Help how to simulate sendkeys in Vista?

    I found this code here in vbforums. Works great.

    Save the code below to a module

    Module Code:
    1. Option Explicit
    2.  
    3. Private Const KEYEVENTF_KEYUP = &H2
    4. Private Const INPUT_KEYBOARD = 1
    5.  
    6. Private Type KEYBDINPUT
    7.     wVk As Integer
    8.     wScan As Integer
    9.     dwFlags As Long
    10.     time As Long
    11.     dwExtraInfo As Long
    12. End Type
    13.  
    14. Private Type GENERALINPUT
    15.     dwType As Long
    16.     xi(0 To 23) As Byte
    17. End Type
    18.  
    19. Private Declare Function SendInput Lib "user32.dll" (ByVal nInputs As Long, pInputs As GENERALINPUT, ByVal cbSize As Long) As Long
    20. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)
    21.  
    22. Public Function SendKeysA(ByVal vKey As Integer, Optional booDown As Boolean = False)
    23.  
    24. Dim GInput(0) As GENERALINPUT
    25. Dim KInput As KEYBDINPUT
    26.  
    27. KInput.wVk = vKey
    28.  
    29. If Not booDown Then
    30.     KInput.dwFlags = KEYEVENTF_KEYUP
    31. End If
    32.  
    33. GInput(0).dwType = INPUT_KEYBOARD
    34. CopyMemory GInput(0).xi(0), KInput, Len(KInput)
    35. Call SendInput(1, GInput(0), Len(GInput(0)))
    36.  
    37. End Function

    Then put this code to a form. Be sure the KEY PREVIEW of the form is set to TRUE

    Form Code:
    1. Private Sub Form_KeyPress(KeyAscii As Integer)
    2. If KeyAscii = vbKeyReturn Then
    3.    SendKeysA vbKeyTab, True
    4.    KeyAscii = 0
    5. End If
    6. End Sub

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