Can someone provide a simple C++ example of using SendInput to send the
number 5 to Notepad in 20 lines of code or less? |
Request for Question Clarification by
keystroke-ga
on
31 Jul 2006 13:11 PDT
I believe these two items will help you
http://msdn.microsoft.com/msdnmag/issues/05/01/CQA/
http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_21119534.html
#define _WIN32_WINNT 0x0501
#include <windows.h>
#include <iostream>
using namespace std;
void main()
{
char end;
HWND windowHandle = FindWindow(0, "test.txt - Notepad");
INPUT *key;
if(windowHandle == NULL)
cout << "not found";
SetForegroundWindow(windowHandle);
Sleep(1000);
key = new INPUT;
key->type = INPUT_KEYBOARD;
key->ki.wVk = 41;
key->ki.dwFlags = 0;
key->ki.time = 0;
key->ki.wScan = 0;
key->ki.dwExtraInfo = 0;
SendInput(1,key,sizeof(INPUT));
key->ki.dwExtraInfo = KEYEVENTF_KEYUP;
SendInput(1,key,sizeof(INPUT));
cout << "key inputted";
cin >> end;
}
Let me know if it points you in the right direction.
--Keystroke-ga
|
Request for Question Clarification by
keystroke-ga
on
31 Jul 2006 13:13 PDT
You will also need to have open a notepad file called "test.txt".
Otherwise this wont work.
--Keystroke-ga
|
Clarification of Question by
jamest-ga
on
31 Jul 2006 13:38 PDT
The second link (experts-exchange.com) looks like it should work, but
the person posting states that it does not work: "Can someone please
tell me what I'm doing wrong in my code and how to fix please?"
|
Request for Question Clarification by
keystroke-ga
on
31 Jul 2006 15:04 PDT
The answer is at the bottom of the page
"SendInput(1,key,sizeof(key));
replace with:
SendInput(1,key,sizeof(INPUT));
sizeof(key) is 4 sins key is pointer."
I already merged his code in with the original posters. I do not have
a c++ compiler on this machine so I cannot test it myself, also my C++
knowledge is a little rusty :)
--Keystroke-ga
|
Clarification of Question by
jamest-ga
on
31 Jul 2006 18:03 PDT
Great! This is the first question I have ever posted. How do I accept your answer?
|