I was wondering if anyone could help me compile code which will actually work for my comiler. I've found many examples and two good references for...

keyboard
http://www.codeproject.com/KB/system/keyboard.aspx

and mouse
http://msdn.microsoft.com/en-us/library/ms646260

...but have never actually gotten a working version to run and therefore haven't been able to fiddle around with functions and learn much about how these event functions work.

-If someone has a bit of code to set pointer to 100,100 on the screen, click, and type a couple letters, that would be great.

I'm using Microsoft Visual Studio 2010 Express
Vista 64-bit OS

Thanks in advance and I appreciate it so, SO much.

If you are trying to do console programming then you should be using the MS-Windows Console Functions. Moving the mouse pointer to some screen location will not allow you to start typing at that location, you have to move the cursor

Example console program

#include <iostream>
#include <Windows.h>

using std::cout;

int main()
{
    HANDLE StdOut = GetStdHandle(STD_OUTPUT_HANDLE);
       
    COORD c = {5,10};
    SetConsoleCursorPosition(StdOut,c);
    cout << "Hello World\n";
}

Oh sorry...I meant the mouse position, not cursor position. That was very cool though. I wanted to move the mouse to an absolute position on the screen. My resolution is set at 1280 x 720 and I wanted to move it over a certain pixel or a certain percentage accross the screen based on a variable. Either would work for what I'm trying to do. Thanks

So you're trying to write a 'bot which might, for example, automatically click into the fields on a displayed web-page and enter specific text data for you?

Anyway as far as your mouse-link, the first note at the top of the page says the function has been superseded, and provides a link to the updated function to use instead. As far as "getting code to compile using your compiler", it looks like you're one of very few users on this forum using the latest and greatest tools on Windows, so what exactly is the problem you're having compiling your code?

I have a difficult time interpreting the MSDN webpages. I've never had a computer programming class so some of the programming syntax that is obvious to others is probably what is messing me up most of the time. I found a solution but Downloaded Dev-C++ 4.9.9.2 to compile it. It shows a simple example of how to use code to move the mouse, and press alt+tab, then right & left click.

#include <windows.h>

int main () {

        while (true) {
        Sleep(5000);
        SetCursorPos(500, 500);
        Sleep(5000);
        keybd_event(VK_MENU,0xb8,0 , 0); //Alt Press
keybd_event(VK_TAB,0x8f,0 , 0); // Tab Press
Sleep (5000);
keybd_event(VK_TAB,0x8f, KEYEVENTF_KEYUP,0); // Tab Release
keybd_event(VK_MENU,0xb8,KEYEVENTF_KEYUP,0); // Alt Release
Sleep(1000);
mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); // Left <strong class="highlight">click</strong>
mouse_event(MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0); // Right <strong class="highlight">click</strong>
Sleep(1000);
        
        
    }

    return 0;
}

Sites I used for this project:

http://www.daniweb.com/software-development/cpp/threads/123456
(mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); // Left <strong class="highlight">click</strong>
mouse_event(MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0); // Right <strong class="highlight">click</strong>)


http://forum.codecall.net/classes-code-snippets/13649-c-keyboard-mouse-emulation.html
(where it says "A crazy mouse gone wild!!")


http://www.codeproject.com/KB/system/keyboard.aspx
(In the example code section toward the bottom

Thanks for the help and hope I have been able to help someone with a similar problem as what I had.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.