Mouse Input

I need to know how to get the coordinates of the cursor and whether or not the left and right buttons are pushed.
I was doing MFC, but the WindowProc function wasn't being called fast enough so I setup a thread to loop and update the mouse position/buttons, but I don't know how to get the values.

Thx

The Genesis
[hr]
The name is Genesis, PhyloGenesis.

Comments

  • : I need to know how to get the coordinates of the cursor and whether or not the left and right buttons are pushed.
    : I was doing MFC, but the WindowProc function wasn't being called fast enough so I setup a thread to loop and update the mouse position/buttons, but I don't know how to get the values.
    :
    : Thx
    :
    : The Genesis
    : [hr]
    : The name is Genesis, PhyloGenesis.
    :


    read MSN for the descrpition of WM_MOUSEMOVE and other mouse related messages. the mose position is in wParam, (or maybe lParam).

    The mouse messages are only sent to the window's thread, so I setting up another thread for them is of no help to you because that thread will not get the messages.

    Maybe you need to rethink your design and start using DirectX engine which you can download free from M$.

  • : I need to know how to get the coordinates of the cursor and whether or not the left and right buttons are pushed.
    [code]
    POINT pos;
    bool left = false;
    bool right = false;

    GetCursorPos(&pos);
    left = GetAsyncKeyState(VK_LBUTTON) & 0x8000;
    right = GetAsyncKeyState(VK_RBUTTON) &0x8000;
    [/code]
  • : : I need to know how to get the coordinates of the cursor and whether or not the left and right buttons are pushed.
    : [code]
    : POINT pos;
    : bool left = false;
    : bool right = false;
    :
    : GetCursorPos(&pos);
    : left = GetAsyncKeyState(VK_LBUTTON) & 0x8000;
    : right = GetAsyncKeyState(VK_RBUTTON) &0x8000;
    : [/code]
    :

    (Haven't tried it yet but it should work.)
    Thanks, and to stober, I know all about the WM_MOUSEMOVE message and parameters. In a Win32 application, the messages get sent to the WinProc function, which I was using, but like I was saying, it wasn't fast enough.
    My program is emulating a DOS interface and I must therefore draw the mouse myself (I used a cursor that looks like it but it doesn't move the same). I'm not trying to setup a thread that will receive the message, I meant I want my thread to do like above, like what Windows does. Windows checks the mouse, and if it moves, sends that message I presume, I needed to do that myself.

    Anyways, thx to both of you anyway.

    Keneniah
    [hr]
    The name is Genesis, PhyloGenesis.

  • : [code]
    : POINT pos;
    : bool left = false;
    : bool right = false;
    :
    : GetCursorPos(&pos);
    : left = GetAsyncKeyState(VK_LBUTTON) & 0x8000;
    : right = GetAsyncKeyState(VK_RBUTTON) &0x8000;
    : [/code]
    :

    This gives me a compiler warning about setting a bool to an int return value and something else too. More specifically
    c:program filesmicrosoft visual studiomyprojects
    ew qbasicmouse.cpp(73) : warning C4800: 'short' : forcing value to bool 'true' or 'false' (performance warning)
    c:program filesmicrosoft visual studiomyprojects
    ew qbasicmouse.cpp(73) : warning C4806: '&' : unsafe operation: no value of type 'bool' promoted to type 'const int' can equal the given constant
    c:program filesmicrosoft visual studiomyprojects
    ew qbasicmouse.cpp(74) : warning C4800: 'short' : forcing value to bool 'true' or 'false' (performance warning)
    c:program filesmicrosoft visual studiomyprojects
    ew qbasicmouse.cpp(74) : warning C4806: '&' : unsafe operation: no value of type 'bool' promoted to type 'const int' can equal the given constant

    What do I do?!

    PhyloGenesis
    [hr]
    The name's Genesis, PhyloGenesis.

  • :
    : What do I do?!
    :

    use the right data type! If you don't know what it is, then look those functions up in MSDN at www.msdn.microsoft.com
  • Sorry for the error, here's the correction:
    [code]
    POINT pos;
    bool left = false;
    bool right = false;

    GetCursorPos(&pos);
    if(GetAsyncKeyState(VK_LBUTTON) & 0x8000) left = true;
    else left = false;
    if(GetAsyncKeyState(VK_RBUTTON) & 0x8000) right = true;
    else right = false;
    [/code]

  • Thx, I was worried.
    I knew it was returning int and I was using bool, but I also knew you said to use bool and that the mouse buttons only use two's state. That is why I wasn't sure what I needed to do.

    This should be perfect. Thx.

    Phylo

    [hr]
    The name's Genesis, PhyloGenesis.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories