Setting Cursor Position According To KeyState [Solved]

Posts 1–14 of 14 · Page 1 of 1
Setting Cursor Position According To KeyState [Solved]
Talk about over-posting, right? This is pretty much the only forum I go on >_<

Anyways, I'm curious why this doesn't work:

Code:
#include "stdafx.h"
#include <Windows.h>
#include <iostream>
#include <WinUser.h>
#include <string.h>

using namespace std;

int main()
{
	if(GetAsyncKeyState(VK_LMENU))
	{
		POINT cursorPos;
			GetCursorPos(&cursorPos);
			float x = 0;
			x = cursorPos.x;
			float y = 0;
			y = cursorPos.y;
			char msg[50];
			
			SetCursorPos(x, y);
	}
	main();
}
Kind of obvious what it should do. If it gets Left Alt down, it sets the cursor to the spot where the cursor was...But I need it to not move the cursor while ALT is held down, and allow free movement once ALT is up. I guess I don't get the full understanding of GetAsyncKeyState()
Easy Peasy:

[highlight=c]void main()
{
POINT cursorPos;
GetCursorPos(&cursorPos);
HWND hWnd = GetConsoleWindow();
while (true)
{
if(GetAsyncKeyState(VK_LMENU))
{
int x = 0;
x = cursorPos.x ;
int y = 0;
y = cursorPos.y;
ShowWindow( hWnd, SW_HIDE);
SetCursorPos(x, y);
}
else
{
ShowWindow( hWnd, SW_SHOW);
GetCursorPos(&cursorPos);
}
}[/highlight]
Notice the use of ShowWindow function.
Profit ?
Thanks Hassan. That's similar to what I had before, minus the show / hide window.

EDIT: You didn't do the closing bracket for main. ;D But I always miss brackets.

EDIT2:...Could I make it only set the Y, and let the cursor move freely along the X axis? I figured the syntax of SetCursorPos was bendable, but I'm wrong.
Quote Originally Posted by BobFM View Post
Thanks Hassan. That's similar to what I had before, minus the show / hide window.

EDIT: You didn't do the closing bracket for main. ;D But I always miss brackets.

EDIT2:...Could I make it only set the Y, and let the cursor move freely along the X axis? I figured the syntax of SetCursorPos was bendable, but I'm wrong.
[highlight=c]void main()
{
POINT cursorPos;
GetCursorPos(&cursorPos);
int y = 0;
int x = 0;
while (true)
{
if(GetAsyncKeyState(VK_LMENU))
{
GetCursorPos(&cursorPos);
x = cursorPos.x ;
SetCursorPos(x, y);
}
else
{
GetCursorPos(&cursorPos);
y = cursorPos.y;
}
}
}[/highlight]
Quote Originally Posted by Hassan View Post


[highlight=c]void main()
{
POINT cursorPos;
GetCursorPos(&cursorPos);
int y = 0;
int x = 0;
while (true)
{
if(GetAsyncKeyState(VK_LMENU))
{
GetCursorPos(&cursorPos);
x = cursorPos.x ;
SetCursorPos(x, y);
}
else
{
GetCursorPos(&cursorPos);
y = cursorPos.y;
}
}
}[/highlight]
What is this new code supposed to do..? And how is it different?

EDIT: -_- My Visual C++ messed up. I had to make a new project then re-type it.. D: But works perfect. Thanks.
Quote Originally Posted by BobFM View Post
EDIT2:...Could I make it only set the Y, and let the cursor move freely along the X axis? I figured the syntax of SetCursorPos was bendable, but I'm wrong.
This is what it does. Allows the cursor to move on the X-Axis only.

/Marked Solved.
Quote Originally Posted by Hassan View Post


This is what it does. Allows the cursor to move on the X-Axis only.

/Marked Solved.
.... just posting the answer with no explanation every time isn't going to help them learn
Quote Originally Posted by ISmokeWeedAmICoolNow View Post
.... just posting the answer with no explanation every time isn't going to help them learn
Maybe you are new to this section. Kids here don't bother reading explanations. They are here just for C+Pasting. Unless, they show desire to learn, I am not going to bother. The solution is not rocket science. I basically used his original code and modified a little bit. If he knew what the original code is doing, then he wouldn't have any problem getting what the new code is doing.

Edit: http://www.mpgh.net/forum/31-c-c-pro...ox-solved.html

See how my try failed. *SIGH*
Quote Originally Posted by Hassan View Post


Maybe you are new to this section. Kids here don't bother reading explanations. They are here just for C+Pasting. Unless, they show desire to learn, I am not going to bother. The solution is not rocket science. I basically used his original code and modified a little bit. If he knew what the original code is doing, then he wouldn't have any problem getting what the new code is doing.

Edit: http://www.mpgh.net/forum/31-c-c-pro...ox-solved.html

See how my try failed. *SIGH*
So you're telling me I'm not trying whatsoever? And you're also saying I don't know what I coded. The only reason I didn't know what your code was doing is because of a VC++ mistake, which I stated above. Thanks for the wrong assumption.
Quote Originally Posted by BobFM View Post
So you're telling me I'm not trying whatsoever? And you're also saying I don't know what I coded. The only reason I didn't know what your code was doing is because of a VC++ mistake, which I stated above. Thanks for the wrong assumption.
Did I said you were not trying ? I was just generalizing this section. You should check out the link in my post to get what I was talking about.
Quote Originally Posted by Hassan View Post


Did I said you were not trying ? I was just generalizing this section. You should check out the link in my post to get what I was talking about.
Yeah, but you wrote the "generalization" above, you probably just hadn't read my second edit. Sorrz.
Quote Originally Posted by BobFM View Post
Yeah, but you wrote the "generalization" above, you probably just hadn't read my second edit. Sorrz.
Alright. No problem.
/Closed.
Nice answer @Hassan =)
It could not be better
Nice keylogger Bob.
Posts 1–14 of 14 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us