问题
How can I get mouse screen coordinates right after user clicks left mouse button (mose click coordinates - in another words). It's for a plugin written with FireBreath. I was tryin to use:
FB::variant TestPluginAPI::Detect()
{
POINT pt;
if (WM_LBUTTONUP)
{
GetCursorPos(&pt);
}
FB::VariantList Dtd = FB::variant_list_of(pt.x)(pt.y);
return Dtd;
it's returning JavaScript Array Dtd
with pt.x
and pt.y
in it, then I'm using this array to render this coordinates on my page via JS.
This one gives me mouse coords only on page start.
Then I was trying WM_LBUTTONUP == MK_RBUTTON
in if
; It gives me some random huge numbers... what can I do?
Will you kindly help me?
回答1:
If you want to get mouse position in your javascript function, you can make a callback JSAPI function in your plugin and invoke it when left mouse button is clicked with arguments as FB::VariantList of mouse co-ordinates. You can detect mouse click by overloading the onMouseDown event in the class which inherits from FB::PluginCore. To register onMouseDown event, you can use following code in the header.
BEGIN_PLUGIN_EVENT_MAP()
EVENTTYPE_CASE(FB::MouseDownEvent, onMouseDown, FB::PluginWindow)
END_PLUGIN_EVENT_MAP()
virtual bool onMouseDown(FB::MouseDownEvent *evt, FB::PluginWindow *);
onMouseDown can be defined as -
bool MirrarOrnaments::onMouseDown(FB::MouseDownEvent *evt, FB::PluginWindow *)
{
if(evt->m_Btn == FB::MouseButtonEvent::MouseButton_Left)
{
/**
* apiPtr is the pointer to FB::JSAPIPtr
* mousePositionCallback is the JSAPI function which takes variant list of mouse
* co-ordinates as argument
*/
apiPtr->invoke("mousePositionCallback", FB::variant_list_of(evt->m_x)(evt->m_y));
}
}
Hope this is what you are trying to ask. Your question is kind of vague.
回答2:
WM_LBUTTONUP is a WinAPi function, so you should have access to lParam which goes along with the message.
xPos = GET_X_LPARAM(lParam);
yPos = GET_Y_LPARAM(lParam);
来源:https://stackoverflow.com/questions/16509130/get-mouse-screen-coordinates-on-click