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:
SendKeys "+(^(%(O)))"
nor
VB Code:
SendKeys "+(^%O"
or anything I've tryed... :(
Printable View
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:
SendKeys "+(^(%(O)))"
nor
VB Code:
SendKeys "+(^%O"
or anything I've tryed... :(
hummm... did you tryTo send the micro Farad symbol to NotePad in one of my app, I used:VB Code:
SendKeys "^%+(keytosend)"Cheers!VB Code:
SendKeys "^%(m)"
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:
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)
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!
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... :p)
Quote:
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!
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
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!
Yes there is, hold on I have to search for them.
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
I downloaded a great sendkey class from vbaccelarator (search steave Mcmohan send key )
Thanks a lot everybody :), I'll test it, everything should be fine now :D.
ARH, IT'S STILL NOT WORKING!!! :mad:
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... :confused:
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
Actually change the asc to this.
VB Code:
Const VK_N = &H4E SendMessage lHwnd, WM_KEYDOWN, VK_N, 0
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...)
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
Sorry for the delay... if you still need the code sample I was talking about, here it is. :blush:
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! :wave:
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
Sounds like you are just trying to execute the shortcut onQuote:
I have a shortcut on my desktop to notepad, It's properties are meant to be executed if I press Ctrl + Alt + N,
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 :confused: :D 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! :p)!!!Quote:
Originally Posted by RobDog888
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!! :D
Yo RobDogg888. I think you better change your signature. This feature apparently no longer exists!
Please usetags when posting code.VB Code:
Your code here