Advertisement

forced key presses

Started by January 11, 2005 09:14 PM
17 comments, last by Drew_Benton 20 years, 1 month ago
Quote:
Original post by raptorstrike
actaully i dont have MVC++, is there any other way that i could get prosses names? would (ctrl + alt + delete) then right click on app then "goto prosses" give me the correct name?

thanks again for your help


Well there are various utilities that can do this for you that are custom made. You could do a search for EnumWindows and EnumChildWindows for examples of programs that do this. Check your PM for what you need [smile]. Let me know if you need any additional files to run it.

- Drew
wow your the best man thanks a ton for all your help on this matter [grin]
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
Advertisement
Not a problem!
ok im going for somthing a little bit trickier, could you write to a java app that takes keyboard input? i have spy++ up and running and when im in the window browser i have an Edit box but i dont think that this is what i need, problem is that an internet browser has so many places to type in stuff and when i do a window search with spy++ it gives me this whole window and not just the edit box, for example if you go to post a message on this site you click the post reply then a window comes up then within that window you have a wite box but how do i sent messages to just that white box not the whole window thanks agin[smile]
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
Quote:
Original post by raptorstrike
ok im going for somthing a little bit trickier, could you write to a java app that takes keyboard input? i have spy++ up and running and when im in the window browser i have an Edit box but i dont think that this is what i need, problem is that an internet browser has so many places to type in stuff and when i do a window search with spy++ it gives me this whole window and not just the edit box, for example if you go to post a message on this site you click the post reply then a window comes up then within that window you have a wite box but how do i sent messages to just that white box not the whole window thanks agin[smile]


Well let me tell you that I do not have any experience in Java, so I can't help you there. As for internet stuff, that is more of an advanced subject that is really hard to get done. I do not know of any types of tutorials or such that can teach how to do web pages like that but I do know the process for C++. The way you have to design the program is like this:

1. Bring the window you are wanting to do whatever in into focus. If you remember how to get that handle of the window, you can use SetFocus().

2. In the program that you made, it must send in keystroks to the window - but you will have to take into account the layout of the page.

For example, if you go to google.com, you will see that the cursor is set to the edit box. If you were automating the process, you would first have to send in each keystroke to the window (reason why it has to be in focus) for the text. After all the text is in, you will have to send in an enter keystroke to start searching.

You will use that generic process to auto do whatever you want - but the big problem is that the window has to be in focus. If the user brings up another window, the key storkes may not get processed.

Basically note the layout of the site you are wanting to automate events in. Note how many tabs it takes to get to each element. You will have to plan that out. Then you can use that text method to paste in strings. Do you kind of see what you have to do now?

- Drew
ok im very close now, i just need to know how you would sent the tab key as an event like VK_TAB what kind of function would you pass this into to make it take effect on the window like how you were saying
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
Advertisement
Quote:
Original post by raptorstrike
ok im very close now, i just need to know how you would sent the tab key as an event like VK_TAB what kind of function would you pass this into to make it take effect on the window like how you were saying


Ok this is what you need to do:

Going back to the first example - here is a demo of what will be done:

int main(){	HWND notepad = FindWindow("Notepad","Untitled - Notepad");	if( !notepad )	{		cout  << "Cannot find window!";		return 0;	}	::Sleep(5000);	SetForegroundWindow(notepad); // bring up the window	SetFocus(notepad); // set focus	keybd_event(VK_SHIFT, 1, 0, 0);	keybd_event(VkKeyScan('*'), 1, 0, 0);	keybd_event(VkKeyScan('*'), 1, KEYEVENTF_KEYUP, 0);	keybd_event(VkKeyScan('*'), 1, 0, 0);	keybd_event(VkKeyScan('*'), 1, KEYEVENTF_KEYUP, 0);	keybd_event(VkKeyScan('*'), 1, 0, 0);	keybd_event(VkKeyScan('*'), 1, KEYEVENTF_KEYUP, 0);	keybd_event(VK_SHIFT, 1, KEYEVENTF_KEYUP, 0);	keybd_event(VK_RETURN, 1, 0, 0);	keybd_event(VK_RETURN, 1, KEYEVENTF_KEYUP, 0);	return 0;}


Basically this will send three * keystorkes to the window that has focus. If you openup notepad and then run this you will see the *'s come on the screen after 5 seconds. The notepad window will come to focus.

Now for your program:
int main(){	HWND notepad = FindWindow("Notepad","Untitled - Notepad");	if( !notepad )	{		cout  << "Cannot find window!";		return 0;	}	::Sleep(5000);	SetForegroundWindow(notepad); // bring up the window	SetFocus(notepad); // set focus		keybd_event(VK_TAB, 1, 0, 0); // send in a tab	keybd_event(VK_TAB, 1, KEYEVENTF_KEYUP, 0);		keybd_event(VK_RETURN, 1, 0, 0); // send in a return	keybd_event(VK_RETURN, 1, KEYEVENTF_KEYUP, 0);	return 0;}


- Drew
ok i finally got it up and running and am able to use it for my perposes thanks again i would give you another rating ++ but i cant lol [grin]
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
Quote:
Original post by raptorstrike
ok i finally got it up and running and am able to use it for my perposes thanks again i would give you another rating ++ but i cant lol [grin]


Hehehe no problem! Glad everythings working great. Hopefully this thread will be of some use to someone else as well.

- Drew

This topic is closed to new replies.

Advertisement