|
|
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
|
|
|
|

|
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++?
|
|
|
|

|
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
|
|
|
|

|
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
|
|
|
|
|

|
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.
|
|
|
|

|
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
|
|
|
|

|
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
|
|
|
|

|
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 ||
|
|
|
|

|
hi,
the program is great, but..
is there a way to do a cycle, i.e. pressing enter every 30 sec until i stop sendkeyssample?
cheers
Andy
|
|
|
|

|
Is there a way to send key input directly to an application without the application having input focus? Say an application that is minimized.
|
|
|
|

|
i am stuck up i need a character for space character using this
sendkey class for visual c++
|
|
|
|

|
I am trying to compile the program? but it always has compile errors, I wonder if it can be compiled in dev-c++? what's wrong? and how? many thanks!
Frank
|
|
|
|

|
Hello
Josh Nimoy contributed some code to this project. I didn't have time to update my code, thus the changes are found here:
http://lgwm.org/downloads/sendkeys2005.zip
as they were submitted to me.
|
|
|
|

|
if i need in addition to sending keys but also mouse event(click some button or ..), how can i achieve it?
|
|
|
|
|
|

|
Hello
Many users reported problems in the code, and many users corrected their own problems.
I am unable to maintain the code any longer, sorry for inconvenience.
Anyone is welcome to post a link to an updated and/or modified version of this library.
Regards,
Elias
|
|
|
|

|
There seems to be a little mistake in the code, when sending "{VKEY X}".
I seems to me that "NumTimes" isn't been set. This makes the program send thousands of key messages, when I try with "{VKEY 13}" for example.
The correction I thought up is to change the line:
WORD MKey, NumTimes;
to:
WORD MKey, NumTimes = 1;
(It's line 370 in SendKeys.cpp)
so that if the value is changed afterwards, it isn't a problem.
I don't know if this is the best solution, but at least it works for me...
Hope that help.
Regis
|
|
|
|

|
How to post Unicode characters? I tried this...
%({NUMPAD3}{NUMPAD2}{NUMPAD0}{NUMPAD5})
Alt+3205 is supposed return a unicode character.
|
|
|
|

|
First of all, I thank the author very much. I've been looking for a code like this for several days, and then I finally gave up and was about to write my own when I found this. I am truly thankful.
Now, during my testing, I realized that SendKeys("{LEFT}") doesn't work. In fact, when {LEFT} is sent, a left brace (ie, '{') appears.
I believe this is because of the following line.
WORD CSendKeys::StringToVKey(LPCTSTR KeyString, int &idx)
{
...
int cmp = _tcsnicmp(KeyNames[Middle].keyName, KeyString, _tcslen(KeyString))
KeyString is "LEFT".
KeyNames[Middle].keyName is "LEFTBRACE"
The problem is _tcslen(KeyString) is only 4.
I changed it to the following, and it works.
int cmp = _tcsnicmp(KeyNames[Middle].keyName, KeyString, max(_tcslen(KeyString), _tcslen(KeyNames[Middle].keyName)))
|
|
|
|

|
even when I changed the #Define _WIN32_WINNT 0x0400 to #Define _WIN32_WINNT > 0x0400. It complains about this line #if _WIN32_WINNT < 0x0400 in afxv_w32.h. How can I go about this?
|
|
|
|

|
I am facing problems in transferring a long string to an external application. Incase of excel, the string gets transferred up to 270 rows and later for 2 more rows some junk values gets sent.
Is there a limit on the length of the string that can be sent to SendKeys function at once?? I am quite not able to figure out
|
|
|
|

|
Seems when I send a long string, such as
c:\program files\vend\prog name12\images\smalltiff2.tif
the only part that shows up is
files\vend\prog name12\images\smalltiff2.tif
I've tried various forms of delay, etc, to no avail.
This is on windows 2000.
Thanks
-JJ
|
|
|
|

|
Hello
I've made a new project and I included the SendKeys.h and SendKey.cpp.
If I compile the project without any initialisation there was a mistake with the INPUT structure.
I used Visual Studio .NET 2003
The compiler says: undefinied identifier "INPUT" in sendkeys.cpp
What can I do?
|
|
|
|

|
Hi,
how can I simulate the combination ALT+0232?
%{NUMPAD0}{NUMPAD2}{NUMPAD3}{NUMPAD2} does not work.
Thank you,
Stefan
|
|
|
|
|

|
Great bit of code. Just about what I need. Saved me hours of work !
Thanks again
Keep it up !
Phil
|
|
|
|

|
Tried your code, worked fine on a local machine. However, couldn't active and setfocus to a window on a remote machine. Do you have any idea? Thx.
|
|
|
|

|
Me too I have this problem
I am using Visual Studio .NET 2003
And I get the following error:
...sendkeys.cpp(652) : fatal error C1010: unexpected end of file while looking for precompiled header directive
*i've even to add #include "SendKeys.h" to my stdafx.h and TestDlg.h
I have the _WIN32_WINDOWS well define
I can't arrive to found where I can
What is going on?
Thanks
|
|
|
|

|
is it possible to launch for example notepad without the run command?
thanks
|
|
|
|

|
how to send Unicode character in an application .
i know system wide hooking . So using setwindowshookex() , how can i send a unicode character to any application .
masum
|
|
|
|

|
How can i send unicode character to an application or to any application(using setwindowhookex() ,i know using system wide hooking )
masfoy
|
|
|
|

|
Hello,
sometimes, especially under heavy CPU load, the sending engine seems to "forget" some characters... The bug especially happens with special characters like '@'. Is this a known problem? Any idea what causes it and how to fix it?
I cannot give you a sample string which reproduces the bug. It only sometimes happens (maybe one time in 50). Setting a default delay of 10 ms (so the keyboard buffer doesn't overflow) doesn't help either...
Thanks and best regards
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|

|
Compiling...
CProcessMem_demoDlg.cpp
Linking...
CProcessMem_demoDlg.obj : error LNK2001: unresolved external symbol "public: bool __thiscall CSendKeys::SendKeys(char const *,bool)" (?SendKeys@CSendKeys@@QAE_NPBD_N@Z)
CProcessMem_demoDlg.obj : error LNK2001: unresolved external symbol "public: __thiscall CSendKeys::CSendKeys(void)" (??0CSendKeys@@QAE@XZ)
Debug/CProcessMem_demo.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
CProcessMem_demo.exe - 3 error(s), 0 warning(s)
|
|
|
|

|
Hi,
this is masum ,i am worry that it is not working in VC++6 ,i added the calss CSendKeys in a new dialogbox project and shows some errors .
I think you try this in a dialogbox project (VC++6),.if u r success then it will be greate pleaser for me . And please let me know how u have done this.
Waiting for replay.
Mahfuz
|
|
|
|

|
Hi - Great Tool!
From what I can gather, the fix made on 5/21/2005 for {RIGHTBRACE} must have broken the ability to parse things like {DOWN 5} (or {DOWN=5} to repeat the down key five times. Here is what I came up with to fix it. This is the last "else" clause in the "special keys" section. It records the origional length of the string, and then effectively "shortens" it by replacing the space or '=' with a string terminator.
{
size_t t2 = _tcslen(KeyString);
for(p = KeyString; *p ++)
{
if( *p == ' ' || *p == '=') *p=0;
}
MKey = StringToVKey(KeyString, keyIdx);
// Key found in table
if (keyIdx != -1)
{
NumTimes = 1;
// Does the key string have also count specifier?
t = _tcslen(KeyNames[keyIdx].keyName);
if (t2 > t)
{
p = KeyString + t + 1;
// Take the specified number of times
NumTimes = _ttoi(p);
}
if (KeyNames[keyIdx].normalkey)
MKey = ::VkKeyScan(KeyNames[keyIdx].VKey);
}
}
Ray
|
|
|
|

|
I am trying to use SendKeys to launch a screen lock program under XP.
I don't know the App name of the program but it launches with the Windows Key + L or the Ctrl key + space bar. The program responds to these combinations no matter what program is running.
My program calls
m_sk.SendKeys("@L");
or
m_sk.SendKeys("{^Space}");
but neither one has any effect.
Any ideas?
Bob
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
|
A C++ port and enhancement of C#'s / VB's SendKeys function.
| Type | Article |
| Licence | |
| First Posted | 22 Apr 2004 |
| Views | 532,521 |
| Bookmarked | 143 times |
|
|