Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WOKWI simulation behaves different when using a mouse click than when using keyboard shortcut for wokwi-pushbutton #951

Open
GabyGold67 opened this issue Jan 21, 2025 · 10 comments
Labels
bug Something isn't working

Comments

@GabyGold67
Copy link

Describe the bug
In my simulations I found several cases where using the keyboard shortcut to "press" a pushbutton behaves differently than clicking over the pushbutton image. I was working on a much complex project so I had to reduce it pretty much to have a clear idea of what was making the whole system fail. When using the mouse click everything works fine, when using the keyboard the on-screen animation doesn't show the changes in the pin outputs, and sometimes stops the simulation until the key is released (in the most complex cases.

To Reproduce
https://wokwi.com/projects/414436084308322305

Expected behavior
One pushbutton, two leds, a class that models different kind of switches out of a simple pushbutton, the objects might be disabled to ignore the pin input signal. An RTOS timer periodically disables the object to see the behavior of the pushbutton when disabled.
Pressing the pushbutton lights on the green led when the object is enabled, when the timer sets the object as disabled the red led signals it's disabled state and the green led turns off.
Works correctly when pressing the button with the mouse pointer, fails when using the "1" key. The timer is set to change the status every 5000 millisecs, while the change of lighting in the leds is frozen, the timer is still running, as keeping the 1 key pressed will block the animation, but when released the disabled status will keep it's change every 5000 milisecs.

Environment (please complete the following information):

  • OS: Windows 10
  • Chrome
  • Version v132.0.6834.84
  • Also under a virtual machine (VirtualBox) running same Windows 10, VSCode up to date with PlatformIO, the WOKWI plugin enabled.

Additional context
For this pruned example it's easy to see the implications, the https://wokwi.com/projects/415018098762515457 project just went berzek...

@GabyGold67 GabyGold67 added the bug Something isn't working label Jan 21, 2025
@Koepel
Copy link

Koepel commented Jan 21, 2025

Can you try this in the Chrome (or Chrome based) browser ?
When the simulation is running, and if you click on the button to set the focus on the button, does the keyboard "1" then work like the mouse ?

@GabyGold67
Copy link
Author

GabyGold67 commented Jan 22, 2025 via email

@Koepel
Copy link

Koepel commented Jan 22, 2025

I did some test, but the difference between keyboard "1" and mouse click is not clear for me. I think that there is a difference when the focus is on the button or not. Perhaps the keyboard gives repeatedly a "1".

Can you make a better test ? It is not clear what the leds do or should do.

@GabyGold67
Copy link
Author

GabyGold67 commented Jan 22, 2025 via email

@Koepel
Copy link

Koepel commented Jan 22, 2025

When I click on the button fast, then the result is the same in all situations.

@GabyGold67
Copy link
Author

GabyGold67 commented Jan 22, 2025 via email

@Koepel
Copy link

Koepel commented Jan 23, 2025

I can not find a consistent way where a mouse click behaves different than the keyboard "1".
The focus of the browser can be on the diagram field, on the button or on something else. That makes a difference for the keyboard, the mouse click makes sure that the browser focus is okay.
It might also depend on the browser, or the settings of the browser or browser extensions.

@GabyGold67
Copy link
Author

Hi, I agree, if the focus is not set in the diagram field the keyboard strokes are not sensed at all, that's completely reasonable.
But setting the focus on the field diagram by clicking anyware in it's canvas gets it workin, but you couldn't reproduce the behavior difference...
I don't think about nothing browser related , as the VS Code plugin reproduces exactly the same different behavior!!

I'll try to make some more testing tomorrow, focusing in execution priorities and timers callback executions.

@GabyGold67
Copy link
Author

Hi, I finally got some time to check on the simulator different behavior when using the mouse click from the use of the asigned key for a pushbutton and when they DO behave as the same, maybe you can check it from there and identify the source of the differences and maybe make them behave similarly, or make a warning about it.

In that second project you'll easily identify the lines added, as they are aftermarked with comments that start with // Added

What was mainly done is to block temporarily the Arduino loop() by using vTaskDelayUntil(). With that addition using the pushbutton click behaves exactly as using the "1" keyboard keys.

It makes it seem like the click and the keypresses are in different priority levels, but you're the ones who know the simulator internals, I just hope this helps you getting rid of the difference that got me completely nuts over the https://wokwi.com/projects/415018098762515457 project simulation.

Please, comment if you've got to notice the difference.

Thank you.

Gaby.//

@Koepel
Copy link

Koepel commented Jan 27, 2025

I don't know the internals, but I do know that the microcontroller instructions for the Arduino Uno are clock-accurate simulated and the ESP32 has optimizations and runs better when every task has a delay(10);

I tried the two project in the Chromium browser in linux.
In the first project, the leds stay always off. In the second project, they turn on, depending if I keep the button pushed for a long time or just click a few times on it.
In every situation, the behaviour is the same for me. Mouse click or keyboard "1", they behave the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants