简体   繁体   English

点击获取鼠标屏幕坐标

[英]Get mouse screen coordinates on click

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. 它是用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. 它会返回其中包含pt.xpt.y JavaScript数组Dtd ,然后使用此数组通过JS在我的页面上呈现此坐标。 This one gives me mouse coords only on page start. 这仅在页面开始时为我提供了鼠标坐标。

Then I was trying WM_LBUTTONUP == MK_RBUTTON in if ; 然后我在if尝试WM_LBUTTONUP == MK_RBUTTON ; It gives me some random huge numbers... what can I do? 它给了我一些随机的巨大数字...我该怎么办?
Will you kindly help me? 您能帮我吗?

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. 如果要在JavaScript函数中获得鼠标位置,则可以在插件中创建一个回调JSAPI函数,并在使用鼠标坐标FB :: VariantList作为参数单击鼠标左键时调用它。 You can detect mouse click by overloading the onMouseDown event in the class which inherits from FB::PluginCore. 您可以通过重载从FB :: PluginCore继承的类中的onMouseDown事件来检测鼠标单击。 To register onMouseDown event, you can use following code in the header. 要注册onMouseDown事件,可以在标题中使用以下代码。
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 - onMouseDown可以定义为-
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. 您的问题有点含糊。

WM_LBUTTONUP is a WinAPi function, so you should have access to lParam which goes along with the message. WM_LBUTTONUP是WinAPi函数,因此您应该可以访问随消息一起显示的lParam。

xPos = GET_X_LPARAM(lParam); 
yPos = GET_Y_LPARAM(lParam); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM