Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,454 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,957 people online right now. Registration is fast and FREE... Join Now!




Sending Keystrokes to application [C++]

 
Reply to this topicStart new topic

Sending Keystrokes to application [C++], Send keystrokes to Firefox

dwayne
3 Aug, 2008 - 02:06 PM
Post #1

New D.I.C Head
*

Joined: 2 Aug, 2008
Posts: 39


My Contributions
I need to send keystrokes to a FF window, specifically, they need to go to the SWF app that will be open in that FF window. I have yet to find an effective method to perform this operation. I specifically need to send a char array to the window. Here is the code that will utilize this function (so people don't waste bandwidth saying they won't do homework).

C++

#include <iostream>
#include <string>
#include <stdio.h>
#include"combination.h"


using namespace std;
using namespace stdcomb;

void swap(char* first, char* second)
{
char ch = *second;
*second = *first;
*first = ch;
}

int permute(char* set, int begin, int end)
{
int i;
int range = end - begin;
if (range == 1) {
cout << set << endl;
//I want to send this to FF too
} else {
for(i=0; i<range; i++) {
swap(&set[begin], &set[begin+i]); //initial swap
permute(set, begin+1, end); //recursion
swap(&set[begin], &set[begin+i]); //swap back
}
}
return 0;
}



int main()
{
char n[7];
cout << "Please input the text you want (de)scrambled: ";
cin.getline(n, 7);
char r5[]= {n[0], n[1], n[2], n[3], n[4], n[6]}; //5 charecter possibilites
char r4[]= {n[0], n[1], n[2], n[3], n[6]}; //4 charecter possibilites
char r3[]= {n[0], n[1], n[2], n[6]}; //3 charecter possibilites
char r2[]= {n[0], n[1], n[6]}; //2 charecter possibilites

permute(n, 0, strlen(n));
do
{
permute(r5, 0, strlen(r5));
}
while(next_combination(n,n+6,r5,r5+5));

do
{
permute(r4, 0, strlen(r4));
}
while(next_combination(n,n+6,r4,r4+4));

do
{
permute(r3, 0, strlen(r3));
}
while(next_combination(n,n+6,r3,r3+3));

do
{
permute(r2, 0, strlen(r2));
}
while(next_combination(n,n+6,r2,r2+2));
return 0;



}

User is offlineProfile CardPM
+Quote Post

NickDMax
RE: Sending Keystrokes To Application [C++]
3 Aug, 2008 - 02:20 PM
Post #2

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,858



Thanked: 49 times
Dream Kudos: 550
My Contributions
Windows API to the rescue! Generally the function you are looking for is "SendInput"

You can google and find lots of examples of using that function.

In general they way to use it is:

First you need to find the proper window to send the input to and make sure that it is active. Then populate an INPUT structure with the info you wish to pass (mouse movement, key up, key down etc. etc. etc.), and then send the input using SendInput.



User is offlineProfile CardPM
+Quote Post

dwayne
RE: Sending Keystrokes To Application [C++]
3 Aug, 2008 - 04:36 PM
Post #3

New D.I.C Head
*

Joined: 2 Aug, 2008
Posts: 39


My Contributions
Would a little bit of code be too much to ask for? I have never played with windows in C++ before and thus have no idea what to do.

The name of the window (as in display name) is predetermined, how do I set it active with SetWindowPos and then feed my char array into INPUT?

This post has been edited by dwayne: 3 Aug, 2008 - 05:01 PM
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/2/08 03:19PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month