Sign in to follow this  
dan1088352

need c++ help

Recommended Posts

Is this a Win32 program, or is it a console program?

You can simulate a keypress by sending a WM_KEYDOWN message to your window with the function SendMessage.

SendMessage( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam );

where hWnd is the handle to your window. The statement would look like this.

SendMessage(hWnd, WM_KEYDOWN, VK_RETURN, 0);

Share this post


Link to post
Share on other sites
if you mean the user will have to press a key, then look at getch() or bioskey()
if you want the computer to press a key, then just call the same functions as you called when you press that key.

Share this post


Link to post
Share on other sites
Quote:
Original post by dan1088352
this is a console program, I am trying to have it press a key for another program.


What type of program is the other program? if it's a win32 program simply fetching a hwnd to the correct window and using SendMessage will probably suffice

Share this post


Link to post
Share on other sites
I don't think so. :)

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/findwindow.asp

Put shortly:
hWnd = FindWindow(LPCSTR ClassName, LPCSTR WindowName);

Pass NULL for the missing parameters if you only have one of the parameters.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by GotenRulezU
How do you fetch the hwnd of another program? Isn't that illegal?
Hip Hip Cheerio,


Yes, you can get $10,000 fine and/or 5 years in jail.

Share this post


Link to post
Share on other sites
Quote:
Original post by dan1088352
I am trying to get a key gode for a game that I lost the jewl case to, if it is illegal, I am sory.
Apart from being a grey area, you're barking up the wrong tree. Call the company instead. If you have proof of purchase (e.g. a receipt), this should be a cinch.

Share this post


Link to post
Share on other sites
This code works for me. Basically it enumerates through all active windows, find the window with the specified name in the title bar, set it to the foreground, and send a key event to it.

In this particular example, I am looking for a window with the title bar name "My App". If it's found, move it to the foreground and simulate an Enter Key event.


#include <windows.h>
#include <stdlib.h>

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lparam)
{
char name[256];
GetWindowText(hwnd, name, 256);
if(!strcmp(name, "My App"))
{
SetForegroundWindow(hwnd);
keybd_event(VK_RETURN, 0, 0, 0);
}

return TRUE;
}

int main()
{
EnumWindows(EnumWindowsProc, NULL);
return 0;
}

Share this post


Link to post
Share on other sites
The CD key for most games is stored in the registry. If you poke around, depending on the game it is, you can probably find a program created to extract the number for you.

Caveat: Most of these CD key extractors are actually CD key stealers. Disconnect your computer from all networks before running any of them just to be sure you're safe and ensure you're running up to date virus protection software.

There's a ton of genuine key recovery programs out there for applications and the like as well.

The best bet (in my mind) would be to get FileMon and RegMon from SysInternals and prepare yourself for some detective work. FileMon will track all files used while it's running while RegMon will track all registry access. Boot up the game you're trying to get the CD key to with RegMon and FileMon running, join a multiplayer game (or whatever is required to ensure that the game has accessed the CD key), and then quit. Then start pouring through the output of RegMon and FileMon looking for all files and keys the game accessed.

The CD key is on your system *somewhere*. I've rarely seen them encrypted - usually they're plaintext in the registry or a ini file.

SysInternals is at http://www.sysinternals.com. Their software is free, and some comes with source code. A great site.

Share this post


Link to post
Share on other sites
Tybon Posted - 10/18/2004 3:25:01 AM
This code works for me. Basically it enumerates through all active windows, find the window with the specified name in the title bar, set it to the foreground, and send a key event to it.

In this particular example, I am looking for a window with the title bar name "My App". If it's found, move it to the foreground and simulate an Enter Key event.

#include <windows.h>
#include <stdlib.h>

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lparam)
{
char name[256];
GetWindowText(hwnd, name, 256);
if(!strcmp(name, "My App"))
{
SetForegroundWindow(hwnd);
keybd_event(VK_RETURN, 0, 0, 0);
}

return TRUE;
}

int main()
{
EnumWindows(EnumWindowsProc, NULL);
return 0;
}





-it wont let me pass NULL in main(), I have to replace it with a number, is that a problem?

[Edited by - dan1088352 on October 19, 2004 8:50:57 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this