|
-
Aug 26th, 2004, 07:20 AM
#1
Thread Starter
Fanatic Member
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:
nor
or anything I've tryed...
Last edited by Ruku; Dec 3rd, 2004 at 09:51 PM.
-
Aug 26th, 2004, 08:12 AM
#2
Fanatic Member
hummm... did you try
VB Code:
SendKeys "^%+(keytosend)"
To send the micro Farad symbol to NotePad in one of my app, I used:Cheers!
-
Aug 26th, 2004, 09:50 AM
#3
Thread Starter
Fanatic Member
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
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)
-
Aug 26th, 2004, 10:14 AM
#4
Fanatic Member
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!
-
Aug 26th, 2004, 10:20 AM
#5
Thread Starter
Fanatic Member
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!
-
Aug 26th, 2004, 11:33 AM
#6
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Aug 26th, 2004, 11:53 AM
#7
Thread Starter
Fanatic Member
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!
-
Aug 26th, 2004, 11:55 AM
#8
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Aug 26th, 2004, 12:10 PM
#9
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:
Private Const VK_ESCAPE As Long = &H1B
Private Const VK_MENU As Long = &H12
Private Const VK_RMENU As Long = &HA5
Private Const VK_LMENU As Long = &HA4
Private Const VK_CONTROL As Long = &H11
Private Const VK_LCONTROL As Long = &HA2
Private Const VK_RCONTROL As Long = &HA3
Private Const VK_SHIFT As Long = &H10
Private Const VK_RSHIFT As Long = &HA1
Private Const VK_LSHIFT As Long = &HA0
Private Const VK_LWIN As Long = &H5B
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Aug 26th, 2004, 08:05 PM
#10
Hyperactive Member
I downloaded a great sendkey class from vbaccelarator (search steave Mcmohan send key )
Regards,
Vishalgiri Goswami
Gujarat, ( INDIA ).
---------------------
-
Aug 27th, 2004, 01:02 PM
#11
Thread Starter
Fanatic Member
Thanks a lot everybody , I'll test it, everything should be fine now .
-
Aug 30th, 2004, 09:27 AM
#12
Thread Starter
Fanatic Member
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:
keybd_event VK_CONTROL, 0, 0, 0 'Press Key
keybd_event VK_MENU, 0, 0, 0 'Press Key
keybd_event Asc("n"), 0, 0, 0 'Press Key
keybd_event VK_CONTROL, 0, KEYEVENTF_KEYUP, 0 'Release
keybd_event VK_MENU, 0, KEYEVENTF_KEYUP, 0 'Release
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...
-
Aug 30th, 2004, 11:03 AM
#13
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:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
SendMessage lHwnd, WM_KEYDOWN, VK_CONTROL, 0
SendMessage lHwnd, WM_KEYDOWN, VK_MENU, 0
SendMessage lHwnd, WM_KEYDOWN, ByVal ASC("n"), 0
SendMessage lHwnd, WM_KEYUP, ByVal ASC("n"), 0
SendMessage lHwnd, WM_KEYUP, VK_MENU, 0
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Aug 30th, 2004, 11:08 AM
#14
Actually change the asc to this.
VB Code:
Const VK_N = &H4E
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Aug 30th, 2004, 02:28 PM
#15
Thread Starter
Fanatic Member
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.
-
Aug 30th, 2004, 06:13 PM
#16
Here is a good site for API references. Download the API Viewer and/or guide.
allapi.net
VB Code:
Private Const WM_KEYDOWN As Long = &H100
Private Const WM_KEYUP As Long = &H101
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" _
(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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Aug 31st, 2004, 08:40 AM
#17
Fanatic Member
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:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Function VkKeyScan Lib "user32" Alias "VkKeyScanA" (ByVal cChar As Byte) As Integer
Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long
Private Const KEYEVENTF_KEYUP = &H2
Private Const vbKeyShift = &H10
Private Const vbKeyCtrl = &H11
Private Const vbKeyAlt = &H12
Public Sub Send_Keys(KeysToSend As String, WindowToSendTo As Long)
Dim ShiftDown As Boolean, AltDown As Boolean, ControlDown As Boolean
Dim intCount As Integer
Dim mScan As Long
Dim a As Integer
Dim mVK As Long
If KeysToSend = "" Then Exit Sub
If WindowToSendTo = 0 Then Exit Sub
For a = 1 To Len(KeysToSend)
mVK = VkKeyScan(Asc(Mid(KeysToSend, a, 1)))
mScan = MapVirtualKey(mVK, 0)
ShiftDown = (mVK And &H100)
ControlDown = (mVK And &H200)
AltDown = (mVK And &H400)
mVK = mVK And &HFF
Do While GetForegroundWindow() <> WindowToSendTo And intCount < 20
DoEvents
intCount = intCount + 1
SetForegroundWindow WindowToSendTo
Loop
If GetForegroundWindow() <> WindowToSendTo Then Exit Sub
If ShiftDown Then keybd_event &H10, 0, 0, 0
If ControlDown And &H200 Then keybd_event &H11, 0, 0, 0
If AltDown And &H400 Then keybd_event &H12, 0, 0, 0
keybd_event mVK, mScan, 0, 0
If ShiftDown Then keybd_event vbKeyShift, 0, KEYEVENTF_KEYUP, 0
If ControlDown Then keybd_event vbKeyCtrl, 0, KEYEVENTF_KEYUP, 0
If AltDown Then keybd_event vbKeyAlt, 0, KEYEVENTF_KEYUP, 0
Next a
SetForegroundWindow Me.hwnd
End Sub
Private Sub Command1_Click()
keybd_event vbKeyCtrl, 0, 0, 0
keybd_event vbKeyAlt, 0, 0, 0
keybd_event vbKeyShift, 0, 0, 0
Call Send_Keys("p", FindHwnd)
keybd_event vbKeyAlt, 0, KEYEVENTF_KEYUP, 0
keybd_event vbKeyCtrl, 0, KEYEVENTF_KEYUP, 0
keybd_event vbKeyShift, 0, KEYEVENTF_KEYUP, 0
End Sub
Private Function FindHwnd() As Long
'Returns the handle of the specified window
FindHwnd = FindWindow("Notepad", vbNullString)
End Function
-
Aug 31st, 2004, 11:05 AM
#18
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
Dec 3rd, 2004, 09:48 PM
#19
Thread Starter
Fanatic Member
Re: Sendkeys, Multiple System Keys [UNRESOLVED]
-
Dec 3rd, 2004, 10:02 PM
#20
Re: Sendkeys, Multiple System Keys [Maybe Resolved]
Yo RobDogg888. I think you better change your signature. This feature apparently no longer exists!
Please use 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|