Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Add key flags to mouse events  (Read 3660 times)

0 Members and 1 Guest are viewing this topic.

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Add key flags to mouse events
« on: January 22, 2015, 06:07:17 pm »
Currently there are only 2ways to check if a mouse click happened with ctrl/system/alt/shift pressed.

1)Use sf::Keyboard::isKeyPressed() which is bad because the event could be delayed due to heavy load...
2)Track the states of the keys yourself. (Sometimes difficult/cumbersome, depends on the code design of course)

I haven't had a look at the implementation of SFML but i think the state of these keys are cached anyways for the key events?

Edit: Ok the states aren't cached, but it could be done the same way as for the key events.


AlexAUT
« Last Edit: January 22, 2015, 06:12:20 pm by AlexAUT »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Add key flags to mouse events
« Reply #1 on: January 22, 2015, 06:12:01 pm »
Nothing is cached, sf::Keyboard::isKeyPressed() will do a direct read of the current keyboard state every time you call it. So there's no chance of "delay" due to heavy load either. So... there's no problem actually; did you face some issue with this?
Laurent Gomila - SFML developer

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: Add key flags to mouse events
« Reply #2 on: January 22, 2015, 06:23:09 pm »
I think you missunderstood me :)

I meant in the time between the mouse-move event gets generated into the window-event-queue and the processing of the event in my code, the states of alt/ctrl... could change. So it would be nice if the event would save the state (like the key events do) of these keys when the event gets generated.

Nvm, i just realized that you can't avoid this problem by my suggestion (Except the event-generation/polling would be done in another thread) :)

AlexAUT
« Last Edit: January 22, 2015, 06:26:50 pm by AlexAUT »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Add key flags to mouse events
« Reply #3 on: January 22, 2015, 07:59:25 pm »
The obvious "solution" (is there a problem here? ...) would be to add the modifier keys to the mouse events too, like some GUI libraries do.
Laurent Gomila - SFML developer

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Add key flags to mouse events
« Reply #4 on: January 22, 2015, 09:03:37 pm »
We could do that, yes, but I feel it's not really necessary: as soon as you want complex mapping you need something more powerful than raw events. And since thor::Action already exists and is working pretty well it seems not really useful to complexify the events for one (of many) corner case. Or am I missing something?
SFML / OS X developer

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: Add key flags to mouse events
« Reply #5 on: January 22, 2015, 11:17:04 pm »
There is no problem anymore  :D It would be nice to have these flags in the mouse events too, but it's not very important.

I came up with the idea because I thought SFML polls the events from the OS in another thread and when you call pollEvent it only returns the events generated by the "polling" thread. Because of that i thought the state of the alt/ctrl/system.. key could change in the time from the "polling from the OS" and the handling of the event in my code.

But since SFML ask for the events from the OS during the window.pollEvent call this isn't a problem.


AlexAUT


Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Add key flags to mouse events
« Reply #6 on: January 22, 2015, 11:21:43 pm »
Don't "think" or "assume", check (or ask) before opening a new feature request ;)
Laurent Gomila - SFML developer

 

anything