Moving Mouse Pointer

This is a discussion on Moving Mouse Pointer within the Windows Programming forums, part of the Platform Specific Boards category; anyone knows how to move the mouse cursor with the keyboard?...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    104

    Moving Mouse Pointer

    anyone knows how to move the mouse cursor with the keyboard?
    Ilia Yordanov,
    http://www.cpp-home.com ; C++ Resources

  2. #2
    Registered User WayTooHigh's Avatar
    Join Date
    Aug 2001
    Posts
    101
    go to Control Panel and click on Accessibility Options. click on the Mouse tab. check Use MouseKeys. on the NumPad, 8 moves pointer up. 2 moves it down. 4 to the left. 6 to the right. 7 up and to left. 9 up and to right. 1 down and to left. 3 down and to right. / make all mouse clicks left button. - make all mouse clicks right button. 0 click and hold. . release click and hold. + double click. 5 single click.
    Sometimes, the farthest point from the center is the center itself.

    Your life is your canvas, it's only as beautiful as you paint it.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    104
    Hehe :-)) I meant how to move the mouse with the keyboard, in C++ :-))

    Thanks for your reply anyway!!!

    If anyone knows how to control my mouse with the keyboard, in C++, please, post here...
    Ilia Yordanov,
    http://www.cpp-home.com ; C++ Resources

  4. #4
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    this should do it,

    Code:
    #include <conio.h>
    #define WIN32_LEAN_AND_MEAN // Exclude Extra Windows Crap
    #define WIN32_EXTRA_LEAN // Exclude More Windows Crap
    #include <windows.h>
    
    void MoveCursorWithKeyboard(void)
    {
        POINT p;
        GetCursorPos(&p);
        char c;
        // Use whatever method you need to get the keys
        // getch is just a function that gets the arrow keys so i use it here
        c = getch();
        if(c == 'M') // Right Arrow Key
            p.x += 1;  // Move Cursor Right
        if(c == 'K') // Left Arrow Key
            p.x -= 1;  // Move Cursor Left
        if(c == 'H') // Up Arrow Key
            p.y += 1;  // Move Cursor Up
        if(c == 'P') // Down Arrow KEy
            p.y -= 1;  // Move Cursor Down
    
        SetCursorPos(p.x,p.y);
    }

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    104
    Hi there!

    I get this when I compile it:
    --------------------Configuration: Cppfasddsfsd2 - Win32 Debug--------------------
    Compiling...
    Cppfasddsfsd2.cpp
    Linking...
    LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
    Debug/Cppfasddsfsd2.exe : fatal error LNK1120: 1 unresolved externals
    Error executing link.exe.

    Cppfasddsfsd2.exe - 2 error(s), 0 warning(s)

    Any ideas?
    Ilia Yordanov,
    http://www.cpp-home.com ; C++ Resources

  6. #6
    Registered User EvenFlow's Avatar
    Join Date
    Oct 2001
    Posts
    422
    If you are using VC++ 6.0 you would need to specify that it is a Windows 32 Application or MFC Application, not a Console application. Check to see if this is what it is saved as, otherwise the compiler won't recognise or validate WinMain(). Try saving it as a .c file if you are not making just a Win32 app. hth.
    Ramble on...

  7. #7
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    it was ment as a stand alone function that you could use in any program, heres a complete example


    Code:
    #include <conio.h>
    #define WIN32_LEAN_AND_MEAN // Exclude Extra Windows Crap
    #define WIN32_EXTRA_LEAN // Exclude More Windows Crap
    #include <windows.h>
    
    void MoveCursorWithKeyboard(char& c)
    {
        POINT p;
        GetCursorPos(&p);
        // Use whatever method you need to get the keys
        // getch is just a function that gets the arrow keys so i use it here
        c = getch();
        if(c == 'M') // Right Arrow Key
            p.x += 1;  // Move Cursor Right
        if(c == 'K') // Left Arrow Key
            p.x -= 1;  // Move Cursor Left
        if(c == 'H') // Up Arrow Key
            p.y += 1;  // Move Cursor Up
        if(c == 'P') // Down Arrow KEy
            p.y -= 1;  // Move Cursor Down
    
        SetCursorPos(p.x,p.y);
    }
    
    int main()
    {
    	char c;
    	while(c != 'q')
    	{
    		MoveCursorWithKeyboard(c);
    	}
    
    	return 0;
    }

  8. #8
    Registered User
    Join Date
    Oct 2001
    Posts
    104
    thank you a lot it's working perfectly
    Ilia Yordanov,
    http://www.cpp-home.com ; C++ Resources

  9. #9
    Former Member
    Join Date
    Oct 2001
    Posts
    955
    but you could also have it working with the arrows and Windows by putting handlers for the WM_KEYDOWN message, and make a switch statement with cases for VK_UP, VK_DOWN, VK_LEFT and VK_RIGHT

    Oskilian

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replace Mouse Pointer?
    By arew264 in forum Game Programming
    Replies: 3
    Last Post: 04-29-2007, 06:27 PM
  2. Question About Pointer To Pointer
    By BlitzPackage in forum C++ Programming
    Replies: 2
    Last Post: 09-19-2005, 11:19 PM
  3. Changing mouse pointer?
    By Matte in forum Windows Programming
    Replies: 9
    Last Post: 11-25-2004, 02:05 PM
  4. Could somebody please help me with this C program
    By brett73 in forum C Programming
    Replies: 6
    Last Post: 11-25-2004, 02:19 AM
  5. changing mouse pointer in c
    By MMM in forum Windows Programming
    Replies: 3
    Last Post: 05-11-2003, 09:28 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21