We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello guys,
As would extract only the code for the numeric part (after the first and before the second colhete), and the number can vary from 1 to 6 digits for example?
I am using this function:
String nomeBotao = cp5_04.window(this).getMouseOverList();
println(nomeBotao);
The reason you need this is that I may control in a single event, several buttons without worrying about the name of each ...
example:
if (cp5_04.isMouseOver(cp5_04.getController("btn1"))){
if (tempoAutClick) verificaTempo();
} else if (cp5_04.isMouseOver(cp5_04.getController("btn2"))){
if (tempoAutClick) verificaTempo();
} else {
clicouMouse = false;
savedTime = millis();
}
Would look like this:
if (cp5_04.isMouseOver(cp5_04.getController(nomeBotao))){
if (tempoAutClick) verificaTempo();
} else {
clicouMouse = false;
savedTime = millis();
}
I hope you understand.
Thank you.
Answers
Hi, if I understood you correctly you are looking for a way to dynamically check if the mouse is inside a certain controller? If yes, the following example might help? (I am using the latest version of ControlP5, 2.2.5)
if you are looking for a solution that checks if the mouseOverList contains any of many Controllers, then the following example will give you some ideas to work with, please see the comments for further details
Hello Sojamo,
Thanks for the feedback, and sorry for my English, I write with the help of Google Translate, my native language is Portuguese ...
You understand perfectly what I need to do, I'm riding a series of buttons dynamically, and then need to know if the focus is positioned on each, to trigger the "Click" automatically, based on a period to be determined.
The example you passed think will work well, but would like to try to complete a medium that I'm trying to do, ie I need to capture part of the array, to a string, so I can use as a button name.
Could you give an example to cut part of the Array for a String, using the tool?
//String nameButton = cp5_05.window(this).getMouseOverList();
For example, it would be cut in positions 2 to 9 ...
You could use substring? But giving type of error in the conversion ...
Below is the code I'm using, to get an idea (is only a part, because the project is divided into parts "Menus")
Below is an print, passing an idea of how is the project.
If you can help me solve this detail, I thank you, anyway is another way you went, you should also work.
Thank you
Hello,
Updated the library, and the second example works perfectly, as expected, now I just need to add as needed in the project.
Thank you,
Hello again,
Unfortunately, some things have not worked after I updated the library ControlP5, need to review some things to upgrade ...
As I said before, it could use String as the return of function?
What is the return type can I use?
In summary, to achieve part of the return cut, ( for example, btn3022 ) can solve the problem.
If you can give some hint of how to do this would be helpful.
Thank you,
Hello again,
I could update the Controlp5 library, to resolve other errors that were occurring ...
Trying to put the code in the Project, gave the error:
The type Controller is ambiguous
Error occurs in this line:
C = Controller (Controller) (cp5_05.getMouseOverList () get (0).);
How do I know who he is in conflict, or rather, how can I solve this?
Again thank you for your attention.
Hi, to answer some questions that were asked above: 1. getMouseOverList() returns a List of Controllers (more specifically Objects that implement the ControllerInterface interface). In most cases the list will contain none or one element (when the mouse is located inside a controller), when Controllers overlap and a mouse inside is detected, the returned list will contain more than 1 elements. To extract the name of an controller, which is of type String, you need to iterate the list and access the name of the Controller with the getName() method:
type Controller is ambiguous means there is more than 1 class that uses the Name Controller. If this is the case, you need to specify and add the Controller's package path:
for(ControllerInterface c:cp5.getMouseOverList()) { controlP5.Controller controller = (controlP5.Controller)(c); println(controller); }
or
controlP5.Controller controller = (controlP5.Controller)(cp5.getMouseOverList().get(0));
hope that helps
Hello,
Thanks for return again ...
I managed to recover the button name the other way, through a arrayList for String, but was giving an error when trying to use the name as a string without using "quotes" in the name to make sure it is on the button (IsMouseOver).
But this otherwise worked well, that's what I needed to do in this case do not even need to know the name of the button, but whether he is about to call the validation time, to do "click" automatic.
The validation code looked like this:
Variable before setup
ArrayList targets = new ArrayList();
In Setup, call function to create objects
And draw looked like this ...
Now continue on with the tests, to perform as expected.
Thank you very very much,> :)
Hello again,
Another detail, I could "simulate" the click-click on the button?
For example, have a control that is enabled (tempoAutClick), call a function to check the time elapsed at that point, if exceeded, I call the "Automatic Click" ...
I tried this way (using mousePressed ()), but is not working.
In Setup()
savedTime05 = millis(); //Salva tempo atual
Function call draw if you're on the button:
If I had run "click" should have performed this function, but it is not running ...
Could you give any suggestions on how to simulate the "Click"
Thank you for your attention again
Ha yes, I missed it when pressed simulates the mouse ...
Thank you
Hello,
I could solve the problem of automatic Click the mouse, using the Robot class, I'll leave some of the code here, because I think it can be useful to someone else.
in draw looked like this:
The function verificaTempo
The function ClikMouse:
Notes: The Click runs in the coordinate that is the mouse ...
Thank you,
Hello,
Continuing disruption to you ...
You can find out some more information about the button, just being the mouse cursor over it, without the need to press?
For example, you need to know what the x and y coordinates, you could not draw ControlEvent function (that is thrown in the mouse Click)
To do this, for to draw a bar (for example) to indicate it is elapsing time, that at a certain time, runs the click of the mouse (Automatic Mouse Click)
Thank you for your attention to whether you can help again.