Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[request] program to get my mouse pos

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
ElectroFusion
Grandmaster Cheater
Reputation: 0

Joined: 17 Dec 2006
Posts: 786

PostPosted: Tue Jun 17, 2008 8:06 pm    Post subject: [request] program to get my mouse pos Reply with quote

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
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Tue Jun 17, 2008 8:22 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Tue Jun 17, 2008 8:48 pm    Post subject: Reply with quote

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.

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
STN
I post too much
Reputation: 43

Joined: 09 Nov 2005
Posts: 2676

PostPosted: Tue Jun 17, 2008 8:49 pm    Post subject: Reply with quote

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.
_________________
Cheat Requests/Tables- Fearless Cheat Engine
https://fearlessrevolution.com
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Tue Jun 17, 2008 9:01 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites