need c++ help

Started by
17 comments, last by dan1088352 19 years, 6 months ago
is there a way to have the computer press a key? I want it to hit enter, is there a way I can do that?
Advertisement
thats an odd question... are you trying to have it press enter for a different program? or you want it to press enter for your own program?
FTA, my 2D futuristic action MMORPG
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);
this is a console program, I am trying to have it press a key for another program.
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.
pex.
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
HardDrop - hard link shell extension."Tread softly because you tread on my dreams" - Yeats
How do you fetch the hwnd of another program? Isn't that illegal?
Hip Hip Cheerio,
-Goten
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.
..what we do will echo throughout eternity..
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.
SendInput().

From MSDN, of course!
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement