Results 1 to 20 of 20

Thread: Sendkeys, Multiple System Keys [Maybe Resolved]

  1. #1

    Thread Starter
    Fanatic Member Ruku's Avatar
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    655

    Question Sendkeys, Multiple System Keys [Maybe Resolved]

    How can I send the keys Ctrl + Alt + Shift + O, for instance using sendkeys (or other API function), this doesn't seem to work:

    VB Code:
    1. SendKeys "+(^(%(O)))"

    nor

    VB Code:
    1. SendKeys "+(^%O"

    or anything I've tryed...
    Last edited by Ruku; Dec 3rd, 2004 at 09:51 PM.

    Using VB.NET 2005/.NET 2.0, NetBeans IDE 5, Fujitsu Cobol85,
    Website: http://DreamForgery.com

  2. #2
    Fanatic Member daydee's Avatar
    Join Date
    Jun 2001
    Location
    Canada
    Posts
    560
    hummm... did you try
    VB Code:
    1. SendKeys "^%+(keytosend)"
    To send the micro Farad symbol to NotePad in one of my app, I used:
    VB Code:
    1. SendKeys "^%(m)"
    Cheers!
    Give your music collection a whole new life with PartyTime Jukebox

  3. #3

    Thread Starter
    Fanatic Member Ruku's Avatar
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    655
    Well, it doesn't seem to be working...! I tested it by trying to make one of my programs runnable by pressing Ctrl + Alt + V with the code

    VB Code:
    1. SendKeys "^%(v)"

    and it doesn't work...! (Don't tell me to shell this program, the means of using the sendkeys are different, But I don't want my project to go open... So I use different examples)

    Using VB.NET 2005/.NET 2.0, NetBeans IDE 5, Fujitsu Cobol85,
    Website: http://DreamForgery.com

  4. #4
    Fanatic Member daydee's Avatar
    Join Date
    Jun 2001
    Location
    Canada
    Posts
    560
    You may have better luck using keybd_event API ?
    I've used this in the past with and worked great to simulate multiple keys being pressed.
    I don’t have a sample right now but will be back home tonight if you’re still interested let me know.
    There's probably a few examples here and there on this forum also.

    Cheers!
    Give your music collection a whole new life with PartyTime Jukebox

  5. #5

    Thread Starter
    Fanatic Member Ruku's Avatar
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    655
    Alrit, looks good, I'll look for keybd_event on the forums until then, I'll be looking at your post tonight If you've still got the sample posted (and if you didn't forget to post it... )
    Originally posted by daydee
    You may have better luck using keybd_event API ?
    I've used this in the past with and worked great to simulate multiple keys being pressed.
    I don’t have a sample right now but will be back home tonight if you’re still interested let me know.
    There's probably a few examples here and there on this forum also.

    Cheers!

    Using VB.NET 2005/.NET 2.0, NetBeans IDE 5, Fujitsu Cobol85,
    Website: http://DreamForgery.com

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Keybd_event api is much better but the program needs
    to be in focus. Not as dependable as SendMessage API.

    Keybd_event

    I would suggest using FindWindow, FindWindowEx, and
    SendMessage APIs to do dependable communications even when
    the window doesn't have the focus.

    HTH
    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

  7. #7

    Thread Starter
    Fanatic Member Ruku's Avatar
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    655
    Thanks for the tip, only the problem stays the same, how can I pass the System keys (ctrl, alt and shift), I can't because it doesn't have an ascii key, any help would be appreciated!

    Using VB.NET 2005/.NET 2.0, NetBeans IDE 5, Fujitsu Cobol85,
    Website: http://DreamForgery.com

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Yes there is, hold on I have to search for them.
    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

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Here they are. I added some more that I thought you may want.
    The VK_L... & VK_R... are for when you want to detect if the left
    ALT,CTL,SHFT keys were pressed or you want to send the left ALT
    key, etc.
    VK_MENU is the generic ALT key.

    VB Code:
    1. Private Const VK_ESCAPE As Long = &H1B
    2.  
    3. Private Const VK_MENU As Long = &H12
    4. Private Const VK_RMENU As Long = &HA5
    5. Private Const VK_LMENU As Long = &HA4
    6.  
    7. Private Const VK_CONTROL As Long = &H11
    8. Private Const VK_LCONTROL As Long = &HA2
    9. Private Const VK_RCONTROL As Long = &HA3
    10.  
    11. Private Const VK_SHIFT As Long = &H10
    12. Private Const VK_RSHIFT As Long = &HA1
    13. Private Const VK_LSHIFT As Long = &HA0
    14.  
    15. Private Const VK_LWIN As Long = &H5B
    16. Private Const VK_RWIN As Long = &H5C
    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

  10. #10
    Hyperactive Member Vishalgiri's Avatar
    Join Date
    Oct 2003
    Location
    India
    Posts
    345
    I downloaded a great sendkey class from vbaccelarator (search steave Mcmohan send key )
    Regards,
    Vishalgiri Goswami
    Gujarat, ( INDIA ).
    ---------------------

  11. #11

    Thread Starter
    Fanatic Member Ruku's Avatar
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    655
    Thanks a lot everybody , I'll test it, everything should be fine now .

    Using VB.NET 2005/.NET 2.0, NetBeans IDE 5, Fujitsu Cobol85,
    Website: http://DreamForgery.com

  12. #12

    Thread Starter
    Fanatic Member Ruku's Avatar
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    655
    ARH, IT'S STILL NOT WORKING!!!

    I have a shortcut on my desktop to notepad, It's properties are meant to be executed if I press Ctrl + Alt + N, It's not working with the following code:

    VB Code:
    1. keybd_event VK_CONTROL, 0, 0, 0                    'Press Key
    2.     keybd_event VK_MENU, 0, 0, 0                    'Press Key
    3.     keybd_event Asc("n"), 0, 0, 0                     'Press Key
    4.  
    5.     keybd_event VK_CONTROL, 0, KEYEVENTF_KEYUP, 0       'Release
    6.     keybd_event VK_MENU, 0, KEYEVENTF_KEYUP, 0      'Release
    7.     keybd_event Asc("n"), 0, KEYEVENTF_KEYUP, 0      'Release

    I figured maybe it needs a DoEvents between the press and release, but no, nothing apears to be working, this problem is a puzzle to my brain...

    Using VB.NET 2005/.NET 2.0, NetBeans IDE 5, Fujitsu Cobol85,
    Website: http://DreamForgery.com

  13. #13
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Your program is still in focus, so its sending keys to you program
    and not the desktop. Like in my previous post, its best to use
    SendMessage API. Get the handel to the desktop and then
    something like this...

    VB Code:
    1. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
    2. ByVal wParam As Long, ByVal lParam As Long) As Long
    3.  
    4.  
    5. SendMessage lHwnd, WM_KEYDOWN, VK_CONTROL, 0
    6. SendMessage lHwnd, WM_KEYDOWN, VK_MENU, 0
    7. SendMessage lHwnd, WM_KEYDOWN, ByVal ASC("n"), 0
    8.  
    9. SendMessage lHwnd, WM_KEYUP, ByVal ASC("n"), 0
    10. SendMessage lHwnd, WM_KEYUP, VK_MENU, 0
    11. SendMessage lHwnd, WM_KEYUP, VK_CONTROL, 0
    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

  14. #14
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Actually change the asc to this.
    VB Code:
    1. Const VK_N = &H4E
    2.  
    3. SendMessage lHwnd, WM_KEYDOWN, VK_N, 0
    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

  15. #15

    Thread Starter
    Fanatic Member Ruku's Avatar
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    655
    Everything looks good, only you forgot (or I'm missin something) to tell me what's the constant value of

    WM_KEYDOWN and WM_KEYUP,

    Or maybe it's just that I don't understand what you meant by "Get the handel to the desktop "

    I think it's done by lHwnd (which I have no idea what value it holds, maybe THERE is the problem...)
    Last edited by Ruku; Aug 30th, 2004 at 02:37 PM.

    Using VB.NET 2005/.NET 2.0, NetBeans IDE 5, Fujitsu Cobol85,
    Website: http://DreamForgery.com

  16. #16
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Here is a good site for API references. Download the API Viewer and/or guide.
    allapi.net
    VB Code:
    1. Private Const WM_KEYDOWN As Long = &H100
    2. Private Const WM_KEYUP As Long = &H101
    3.  
    4. Private Declare Function GetDesktopWindow Lib "user32" () As Long
    5.  
    6. Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" _
    7. (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    8.  
    9. Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" _
    10. (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    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

  17. #17
    Fanatic Member daydee's Avatar
    Join Date
    Jun 2001
    Location
    Canada
    Posts
    560
    Sorry for the delay... if you still need the code sample I was talking about, here it is.
    The FindHwnd() function is most basic and will return Notepad's handle in this case but modify it to send the keys to any window you like.

    In the example below, clicking Command1 will send Ctrl + Alt + Shift + p keys to the Notepad window which produces this odd character --> ¶

    NOTE: For this to work in Notepad, Capital lock on your keyboard has to be "ON".

    Cheers!

    VB Code:
    1. Option Explicit
    2. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    3. Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
    4. Private Declare Function GetForegroundWindow Lib "user32" () As Long
    5. Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    6. Private Declare Function VkKeyScan Lib "user32" Alias "VkKeyScanA" (ByVal cChar As Byte) As Integer
    7. Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long
    8. Private Const KEYEVENTF_KEYUP = &H2
    9. Private Const vbKeyShift = &H10
    10. Private Const vbKeyCtrl = &H11
    11. Private Const vbKeyAlt = &H12
    12.  
    13. Public Sub Send_Keys(KeysToSend As String, WindowToSendTo As Long)
    14.   Dim ShiftDown As Boolean, AltDown As Boolean, ControlDown As Boolean
    15.   Dim intCount As Integer
    16.   Dim mScan As Long
    17.   Dim a As Integer
    18.   Dim mVK As Long
    19.    
    20.     If KeysToSend = "" Then Exit Sub
    21.     If WindowToSendTo = 0 Then Exit Sub
    22.        
    23.     For a = 1 To Len(KeysToSend)
    24.        
    25.         mVK = VkKeyScan(Asc(Mid(KeysToSend, a, 1)))
    26.         mScan = MapVirtualKey(mVK, 0)
    27.        
    28.         ShiftDown = (mVK And &H100)
    29.         ControlDown = (mVK And &H200)
    30.         AltDown = (mVK And &H400)
    31.        
    32.         mVK = mVK And &HFF
    33.        
    34.                
    35.         Do While GetForegroundWindow() <> WindowToSendTo And intCount < 20
    36.             DoEvents
    37.             intCount = intCount + 1
    38.             SetForegroundWindow WindowToSendTo
    39.          Loop
    40.        
    41.         If GetForegroundWindow() <> WindowToSendTo Then Exit Sub
    42.        
    43.         If ShiftDown Then keybd_event &H10, 0, 0, 0
    44.         If ControlDown And &H200 Then keybd_event &H11, 0, 0, 0
    45.         If AltDown And &H400 Then keybd_event &H12, 0, 0, 0
    46.        
    47.         keybd_event mVK, mScan, 0, 0
    48.        
    49.         If ShiftDown Then keybd_event vbKeyShift, 0, KEYEVENTF_KEYUP, 0
    50.         If ControlDown Then keybd_event vbKeyCtrl, 0, KEYEVENTF_KEYUP, 0
    51.         If AltDown Then keybd_event vbKeyAlt, 0, KEYEVENTF_KEYUP, 0
    52.        
    53.     Next a
    54.              
    55.     SetForegroundWindow Me.hwnd
    56.    
    57. End Sub
    58.  
    59. Private Sub Command1_Click()
    60.   keybd_event vbKeyCtrl, 0, 0, 0
    61.    keybd_event vbKeyAlt, 0, 0, 0
    62.     keybd_event vbKeyShift, 0, 0, 0
    63.      Call Send_Keys("p", FindHwnd)
    64.     keybd_event vbKeyAlt, 0, KEYEVENTF_KEYUP, 0
    65.    keybd_event vbKeyCtrl, 0, KEYEVENTF_KEYUP, 0
    66.   keybd_event vbKeyShift, 0, KEYEVENTF_KEYUP, 0
    67. End Sub
    68.  
    69. Private Function FindHwnd() As Long
    70. 'Returns the handle of the specified window
    71.     FindHwnd = FindWindow("Notepad", vbNullString)
    72. End Function
    Give your music collection a whole new life with PartyTime Jukebox

  18. #18
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    I have a shortcut on my desktop to notepad, It's properties are meant to be executed if I press Ctrl + Alt + N,
    Sounds like you are just trying to execute the shortcut on
    your desktop to run notepad, or do you want to control notepad?
    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

  19. #19

    Thread Starter
    Fanatic Member Ruku's Avatar
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    655

    Cool Re: Sendkeys, Multiple System Keys [UNRESOLVED]

    Quote Originally Posted by RobDog888
    Sounds like you are just trying to execute the shortcut on
    your desktop to run notepad, or do you want to control notepad?
    No Rob, I have no means to run notepad, lol, thanks for your concerns though... I'm just trying something interesting and a good way to test whatever I'm hidding would be to run notepad this way, and omg I have totally forgotten about this thread...! It's also been a while since I touched vb6 (.Net rocks! )!!!

    Well, I think I know a place where they still hav vb6 installed, ima test my old app. over there with the new codes from you people,

    thanks again people!!

    Using VB.NET 2005/.NET 2.0, NetBeans IDE 5, Fujitsu Cobol85,
    Website: http://DreamForgery.com

  20. #20
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Sendkeys, Multiple System Keys [Maybe Resolved]

    Yo RobDogg888. I think you better change your signature. This feature apparently no longer exists!

    Please use
    VB Code:
    1. Your code here
    tags when posting code.

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