简体   繁体   中英

FireBreath passing values from one function to another and using that functions in JavaScript

How can i pass ptx and pty from TestPluginAPI::ClickSemulationMove to TestPluginAPI::ClickSemulationClick(int ptx, int pty) .
The thing is that i must use this 2 functions in JavaScript and therefore can't simply expose it from one to another.

FB::variant TestPluginAPI::ClickSemulationClick(int ptx, int pty)
{

ShowCursor(true);
MouseLeft();
MouseReturn(ptx, pty);
ShowCursor(true);
return 0;
}

FB::variant TestPluginAPI::ClickSemulationMove(int ptx, int pty)
{
POINT pt;
MouseMove(-325, 605);
GetCursorPos(&pt);
ptx = pt.x;
pty = pt.y;
return 0;
}

As i get it i need to use JSObjectPtr or FB::VariantList, but i'm bit of confused without any sample. Can anyone show me the simple code sample?

Have you read the JSAPI docs ? All the information is there.

To return an array (will be a javascript array) with two values, you can just do:

return FB::variant_list_of(pt.x)(pt.y);

Then in javascript you could call the other method like:

var res = plugin().ClickSemulationMove(); // Assuming you don't actually need args here
plugin().ClickSemulationClick(res[0], res[1]);

You could also pass the array in directly, in which case you could do something like this in C++:

FB::variant TestPluginAPI::ClickSemulationClick(const std::vector<int>& arr)
{
    ShowCursor(true);
    MouseLeft();
    MouseReturn(arr[0], arr[1]);
    ShowCursor(true);
    return 0;
}

Seriously, there are example of all of these things in the FBTestPlugin example in the FireBreath code base; you should spend some time in there. Most of the questions I see you asking could be quickly discovered for yourself from reading through that code and then you'd understand it better.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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