|
|
Comments and Discussions
|
|
 |

|
I tried to open the solution in VS2010
but I got an error when I try to run the solution
"Unable to start program 'D:\SendKeys\.\Debug\\SendKeysSample.exe'
The system cannot find the file specified"
|
|
|
|

|
I tried to use this code in Qt, but it has this main problem:
error: cannot convert 'const char*' to 'const TCHAR*'
|
|
|
|

|
Thank you for providing this code, it is very useful! However, I found two problems with AppActivate() by window title and class name:
First, this line does not work correctly when compiling for Unicode, leaving garbage in "titleclass" and causing grief later in the search:
memset(titleclass, 0, l1 + l2 + 5);
Should be modified to:
memset(titleclass, 0, (l1 + l2 + 5)*sizeof(TCHAR));
Second, the code in CSendKeys::enumwindowsProc() seems to match any window of the given class name (if wclass is not NULL), regardless of window title provided. The code as provided in this article is:
BOOL bMatch(FALSE);
if (wclass)
{
TCHAR szClass[300];
if (::GetClassName(hwnd, szClass, _countof(szClass)))
bMatch |= (_tcsstr(szClass, wclass) != 0);
}
if (wtitle)
{
TCHAR szTitle[300];
if (::GetWindowText(hwnd, szTitle, _countof(szTitle)))
bMatch |= (_tcsstr(szTitle, wtitle) != 0);
}
To make it work correctly I modified it to:
BOOL bMatch(FALSE);
if (wclass)
{
TCHAR szClass[300];
if (::GetClassName(hwnd, szClass, _countof(szClass)))
bMatch = (_tcsstr(szClass, wclass) != 0);
}
if (wtitle && (!wclass || bMatch))
{
TCHAR szTitle[300];
bMatch = FALSE; if (::GetWindowText(hwnd, szTitle, _countof(szTitle)))
bMatch = (_tcsstr(szTitle, wtitle) != 0);
}
Greg
|
|
|
|

|
Hi,
Can you please tell how it can be achived to send above mentioned keys. I have checked your code and tried to send % key but it didn't worked for me. i am trying to achieve the same in c#.
Thanks in advance
Anant
|
|
|
|

|
Hello,
It is explained in the article.
For example to send "?" , it is Shift+"/". The shift is represented (as per Table 3) by a "+", thus: "?" = "+/"
|
|
|
|

|
Hi, I have inserted SendKeys.h in my project but I have an error in my code relative to SendKeys: the type "const char" is incompatible with "LPTCTSTR"
#include "stdafx.h"
#include "winuser.h"
#include "SendKeys.h"
int main( int argc, char** argv ) {
IplImage* img;
char key = getchar();
CSendKeys sk;
if(key=='q'){
sk.SendKeys("Hello world!");
}
}
modified on Friday, December 3, 2010 5:15 AM
|
|
|
|

|
Hi,
Thanks for your work... really.
I try to send a CTRL+A to Firefox, but it doesn't work, it's fine when I send regular characters, but the soonest I want to send ^A or ^C, nothing happens. It works fine for IE... but not Firefox.
Please help...
|
|
|
|

|
...did not work for me. In AppActivate you set the focus to a window. I've checked in code after the call if the handle is the focused window and it's not!?
Using MS Visual Studio 2005
Found and tried AttachThreadInput(GetCurrentThreadId(), GetWindowThreadProcessId(wnd->m_hWnd, NULL), true) but didn't help.
Any ideas?
|
|
|
|

|
In reading through the description above, it is not clear if the {DELAY 50} syntax just delays the onset of the next key to the KB buffer or whether it holds down the current key for 50ms. The original keyboard_event where you have to specify keydown and then keyup allows you to do this. I have a gaming application where I want to actually "press a key and hold it down until I release it" rather than repeatedly pressing it. Is this possible with Sendkeys C++?
|
|
|
|

|
The same problem. Does anybody know how to simulate this "press a key and hold it down until I release it".
|
|
|
|

|
Hello,
Firstly let me thank you for this excellent class. I would like to point you to a bug that came to light when I tried to add a few keys codes to the list.
In SendKeys.cpp line 325
int cmp = _tcsicmp(KeyNames[Middle].keyName, KeyString, _tcslen(KeyString));
should actually be
int cmp = _tcsicmp(KeyNames[Middle].keyName, KeyString);
This is because the existing code will match even in the following case, since you are forcing it to compare only the first 5 chars
_tcsicmp("RIGHTBRACE", "RIGHT", 5);
As of now, the binary search manages to escape this problem, but you may have problems extending it in the future.
HTH
- Sid
|
|
|
|

|
You are absolutely right. This bug is causing for example F1 key to fail. Thanks I was checking why my code was not working and your comment was very helpful.
|
|
|
|

|
Yes, thank you! I was having a problem with sending {LEFT} due to {LEFTBRACE} being matched. I just changed to {LBRACE} and re-positioned it alphabetically above {LEFT}. Worked like a charm.
|
|
|
|

|
Is it possible to simulate (send) the dead diaeresis (umlaut) followed by a normal letter, with c++ code instead of with the keyboard?
I tried with keybd_event and SendMessage, but I cant get it to work.
SendMessage(hWnd,WM_KEYDOWN,(WPARAM)0x0308,0);
SendMessage(hWnd,WM_DEADCHAR,(WPARAM)0x0308,0);
SendMessage(hWnd,WM_KEYUP,(WPARAM)0x0308,0);
SendMessage(hWnd,WM_KEYDOWN,(WPARAM)0x0075,0);
SendMessage(hWnd,WM_CHAR,(WPARAM)0x0075,0);
SendMessage(hWnd,WM_KEYUP,(WPARAM)0x0075,0);
Thx
|
|
|
|

|
Hiya guys, I had some problems with the ESC key.
Just so you know, when you want to send ESCAPE to a program, This library will send a WM_KEYDOWN message with the parameter Extended set to 0, BUT it will send a WM_KEYUP message with the parameter Extended set to 1!
it caused some problems with one particular program I wanted to control by getting stuck in a loop.
Quick Hotfix:
I changed sendkeys.cpp by removing any references to the KEYEVENTF_EXTENDEDKEY flag so that it will never set this flag to 1 (I loose control of some keys but in my particular case, it does not matter).
Kudos to the author of this program
modified on Friday, November 21, 2008 7:11 PM
|
|
|
|

|
I have problemas doing this. When I add SendKeys.cpp and SendKeys.h to a proyect, I can't compile it. Can it be possible? Could someone do it? =(
I'll thank your help!
|
|
|
|

|
Hi There.
I need some technical help regarding your one of the article i.e., "SendKeys in C++".
Your article is one of the best articles I came across so far. At this point of moment, can you tell me how can I read the text written by your application on the active window?
I mean your application can activate a window and can write text on that window, Can you please help me out reading the same text?
In case you need any further info, then please let me know.
Thanks and Regards.
Pankaj
|
|
|
|

|
Please do not cross-post (or double-post), pick either here or the Lounge, not both.
Peace!
-=- James Please rate this message - let me know if I helped or not!
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|

|
Sorry for that James
|
|
|
|
|

|
I was wondering if someone could create a dll version that can be accessed using the Windows Scripting Host. I don't know C++ (just JScript and VBScript) and don't have any C++ IDEs installed.
Thanks!
|
|
|
|

|
We're writing a Visual C++ application which needs to emulate key-strokes upon a particular event. We've downloaded the code from this sample.
When we add a reference to this project in our Visual C++ project (in Visual Studio .NET 2003) and include the header-files using "#include "SendKeys.h", it gives compilation errors saying "unresolved external symbol public: bool __thiscall CSendKeys::SendKeys". We've also tried importing all the code of the attached project into our project and compiling it from scratch. However, this option does not work as well (though the attached project compiles independently).
Can somebody pls let me know the sequence of steps that we need to follow to include this in our code (separate project) and compile it?
Thanks, Mayank Shridhar.
|
|
|
|

|
Check out this URL that contains a listing of "difficult to diagnose" error messages and possible fixes.
http://averia.unm.edu/VisualCPPErrorMessages.html[^]
It sounds like perhaps you have the .h file included, but don't actually have the class defined in your project.
|
|
|
|

|
Hi
I´ve the same problem did you solve it ? and how? if it's not much problem
thankyou
|
|
|
|

|
I too have same problem:
Errors i am getting on compile time.
Error 1: fatal error C1189: #error : _WIN32_WINNT settings conflicts with _WIN32_IE setting c:\program files\microsoft sdks\windows\v6.0a\include\sdkddkver.h 217 SendKeysSample
If commented the 3 line of code.
Error 2: error C2504: 'ICommDlgBrowser2' : base class undefined c:\program files\microsoft sdks\windows\v6.0a\include\shobjidl.h 6407 SendKeysSample
Please can you correct this and reattached the functioning source code.
|
|
|
|

|
error C2664: 'CSendKeys::SendKeys' : cannot convert parameter 1 from 'const char [27]' to 'LPCTSTR'
says that when i try to compile can any one tell me how to fix
|
|
|
|

|
Hi
Any idea how send keys to active application ? eg ie
Also in notepad if i reduce the time then all of it does not work properly
let's say we do not want delay then what?
Regards
|
|
|
|

|
Hey
I`ve the same problem did you solve it ? and how ? if it's not too much problem..
Regards
|
|
|
|

|
Hi lallous
Your code works great - thank you for the hard work.
I have a C# version of your code if you want. I wrapped the class into a VC++6 DLL and have created marshalled classes within C# - it works.
If you want I can give you the source code so you can look at / post / whatever.
Interested ?
Thanks,
Robert.
modified on Tuesday, April 15, 2008 10:55 PM
|
|
|
|

|
Hello Robert,
Thanks for your efforts.
This sounds a good idea.
Another idea might be to try to compile the project as a class library directly from a C++/CLI projects, probably it will work, thus you will have just one assembly written in mixed code.
I don't know much VB, doesn't VB.NET have a SendKeys functionality? thus if you add appropriate references from C# you can SendKeys as well?
p.s: if you have a website, please post a direct link in a dedicated thread in here.
Regards,
Elias
|
|
|
|

|
My bad - the C# SendKeys actually works fairly well
Oh well - learnt how to wrap C++ classes for C# anyway
|
|
|
|

|
I need to send keypad keys ( not supported via c# sendkey). Although this is an older thread - can I ask for the c# wrapper to: lulej@tpg.com.au
thanks
Andreas
|
|
|
|

|
Hi Robert,
I need a C# version, can you please e-mail it to me or post a link for download?
Thanks,
|
|
|
|

|
what is your email address ?
btw - the native C# SendKeys works perfectly - I am using that constantly and dont touch the dll I made
if you want I can still email you the project though
modified on Tuesday, April 15, 2008 10:56 PM
|
|
|
|

|
Hi,
Can you send me your marshalled C# SendKeys project. I need to send keystrokes to DOS window.
alperonline@hotmail.com
|
|
|
|

|
Just so that everyone knows. The C# SendKeys() doesn't work on DOS mode programs like EDIT.COM but this project does. I converted the entire thing to C#. Its not perfect because I don't know how to do proper marshalling of structs for the enumwindowsProc, but it does work properly (since I'm using FindWindow()/FindWindowEx()).
|
|
|
|

|
Got a download available somewhere? Or can you send it to erikforbes@gmail.com?
PS: This is what part of the alphabet would look like if the letters Q and R were removed.
|
|
|
|

|
Hello,
I would love to have your C# version. Would you be so kind to send it to me at rhe following email address:
jim_greene@jabil.com
Thanks in advance!
Best regards,
Jim
|
|
|
|

|
I have been searching for a way to send the Windows key to another computer with no luck using SendKeys. Your C# code sounds exactly what I am looking for.
Please send a copy to me - internetillusion@yahoo.com
|
|
|
|

|
Hi Robert,
I need a C# version too, can you please e-mail it to me or post a link for download?
Thanks,
Roberto
|
|
|
|

|
Hi!,
can you share the C# version and send it to this mail id:
manish_jain06@infosys.com
regards,
Manish
|
|
|
|

|
Hi Robert,
I would like to get your C# version.
Could you send it to Gicks@free.fr
Thank's a lot.
|
|
|
|

|
Hi,
I know you get a lot of requests like mine but please do share... I have been searching for months for this.
Can you send to laplante_rooster@hotmail.com ?
Thanks for your time and effort!
Dave
|
|
|
|

|
Hi!,
can you share the C# version and send it to the following mail:
Tolis_2001@hotmail.com
Thanks in advance,
Tolis
|
|
|
|

|
Can you please mail me the C#-Version, too?
My e-mail adress: spamarea-scriptmail@yahoo.de
Thank you
|
|
|
|

|
Hi
Can u send the c# version to audi_rs7@yahoo.com ?
Thank you very much
|
|
|
|

|
Hi Robert,
I'm also interest into your translation.
Could you send it to me too?
Thanks
Roberto Guerzoni
|
|
|
|

|
Hi Robert,
I would love to check your code out! Would you be able to email it to micahandkatie@gmail.com ? Thanks! Micah
|
|
|
|

|
I had a strange problem running this on my laptop.
It mostly worked but produced some strange effects such as changing the volume/brightness or activating other function keys.
This seems to be a problem with generating the key up event.
KeyboardEvent(VKey, ScanCode, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP);
This always sets the KEYEVENTF_EXTENDEDKEY flag. Mostly this is harmless, but it seems that the key up events are used by the function key handling on my laptop.
The correct code should only set the flag when it is needed (the same as the key down event).
E.g.
KeyboardEvent(VKey, ScanCode, (IsVkExtended(VKey) ? KEYEVENTF_EXTENDEDKEY : 0) | KEYEVENTF_KEYUP);
|
|
|
|

|
Your article is very very good,no doubt you have done increditable work and made
easy many peoples life like me.
I included your sendkey class .h and .cpp file in project on which I am working but it gives error at INPUT function, and SendInput function. That file is User32.lib file or in windows.h header or winuser.h . I included these files, but it gives error global function not declared. I dont know how to use.
One more thing
in AppActivate function you have written at a place ::SetForeGroundWindow(hwnd)
without which code doesnot give result,but for my application it is unwanted,as
I am behind removing unwanted MessageBox which Earlier engineer left in his dll whos
code is not with me.And I found I can work out well because of your contribution
to universal code.Will you please let me know,how to solve these problems.
|| ART OF LIVING ||
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.
|
A C++ port and enhancement of C#'s / VB's SendKeys function.
| Type | Article |
| Licence | |
| First Posted | 22 Apr 2004 |
| Views | 536,043 |
| Bookmarked | 143 times |
|
|