anyone knows how to move the mouse cursor with the keyboard?
anyone knows how to move the mouse cursor with the keyboard?
Ilia Yordanov,
http://www.cpp-home.com ; C++ Resources
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.
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
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); }
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
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...
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; }
thank you a lot it's working perfectly
Ilia Yordanov,
http://www.cpp-home.com ; C++ Resources
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