 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
ElectroFusion Grandmaster Cheater
Reputation: 0
Joined: 17 Dec 2006 Posts: 786
|
Posted: Tue Jun 17, 2008 8:06 pm Post subject: [request] program to get my mouse pos |
|
|
Title says all. I'm making a thing to scan for me.
_________________
| qwerty147 wrote: |
| ghostonline wrote: |
what world are you in?
|
bera
but i live in NZ
|
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Tue Jun 17, 2008 8:22 pm Post subject: |
|
|
| Code: |
if(GetAsyncKeyState(VK_F12)) {
POINT point;
string points;
string temp;
if(GetCursorPos(&point)) {
sprintf_s(points, 4, "%s", point.x);
strcat(points, ", ");
sprintf_s(temp,3, "%s", point.y);
strcat(points, temp);
MessageBox(NULL, points, "Coords", MB_OK);
}
}
|
Not sure if that's quite the way to use sprintf_s, but eh. You're getting spoonfed anyway.
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Tue Jun 17, 2008 8:48 pm Post subject: |
|
|
| oib111 wrote: | | Code: |
if(GetAsyncKeyState(VK_F12)) {
POINT point;
string points;
string temp;
if(GetCursorPos(&point)) {
sprintf_s(points, 4, "%s", point.x);
strcat(points, ", ");
sprintf_s(temp,3, "%s", point.y);
strcat(points, temp);
MessageBox(NULL, points, "Coords", MB_OK);
}
}
|
Not sure if that's quite the way to use sprintf_s, but eh. You're getting spoonfed anyway. |
I think it would be more efficient to
a) declare point/points globally, so you don't redeclare them each time F12 is hit
b) only use sprintf_s once:
| Code: |
if (GetCursorPos(&point)) {
sprintf_s(points, 21, "Coordinates: %d, %d", point.x, point.y);
MessageBox(NULL, points, "Mouse Coords", MB_OK);
}
|
You should also add error support
| Code: |
..
}
else MessageBox(NULL, "GetCursorPos() failed!", "", MB_OK);
|
I don't feel like incorporating GetLastError() or whatever in the MessageBox, so oh well.
_________________
|
|
| Back to top |
|
 |
STN I post too much
Reputation: 43
Joined: 09 Nov 2005 Posts: 2676
|
Posted: Tue Jun 17, 2008 8:49 pm Post subject: |
|
|
You can use WM_MOUSEMOVE message as well which will notify you as soon as the mouse is moved. The lParam will contain x and y co-ords.
_________________
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Tue Jun 17, 2008 9:01 pm Post subject: |
|
|
Revised code.
| Code: |
POINT point;
string points;
if(GetAsyncKeyState(VK_F12)) {
if(GetCursorPos(&point)) {
sprintf_s(points, "Mouse Coordinates: %d, %d", point.x, point.y);
MessageBox(NULL, points, "Mouse Coords", MB_OK);
}
/*BEGIN OPTIONAL*/
else {
ErrorExit(GetCursorPos);
}
/*END OPTIONAL*/
}
|
If you want to use GetLastError here's the code for the optional function called in the above code:
| Code: |
void ErrorExit(LPWSTR lpszFunction)
{
LPVOID lpMsgBuf;
LPVOID lpDisplayBuf;
DWORD dw = GetLastError();
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0, NULL );
lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT,
(lstrlen((LPCTSTR)lpMsgBuf)+lstrlen((LPCTSTR)lpszFunction)+40)*sizeof(TCHAR));
StringCchPrintf((LPTSTR)lpDisplayBuf,
LocalSize(lpDisplayBuf) / sizeof(TCHAR),
TEXT("%s failed with error %d: %s"),
lpszFunction, dw, lpMsgBuf);
MessageBox(NULL, (LPCTSTR)lpDisplayBuf, TEXT("Error"), MB_OK);
LocalFree(lpMsgBuf);
LocalFree(lpDisplayBuf);
ExitProcess(dw);
}
|
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|