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

Author Topic: Can't make CTRL + mouse wheel work  (Read 3094 times)

0 Members and 1 Guest are viewing this topic.

Riton_Lafouine

  • Newbie
  • *
  • Posts: 16
    • View Profile
Can't make CTRL + mouse wheel work
« on: May 24, 2020, 12:51:05 pm »
Hello,

I'm sure i'm doing something stupid, i tried many combinations without success, certainly a syntax mistake but can't figure out what do do

the problem is that the
if (event.key.control)
is always true event if ctrl key is not pressed

Here is part of my code :

case sf::Event::MouseWheelMoved:
        {
            if(sf::Mouse::HorizontalWheel)
            {
                int8_t delta = event.mouseWheel.delta;
                std::cout << "wheel movement: " << delta << std::endl;
                for(uint16_t i=0; i<selected_chan.size() ;i++)
                {
                    if(ch(selected_chan[i])get_channel_number()!=0)//si le circuit a ete cree
                    {
                        uint8_t res = 0;
                        uint8_t niv = ch(selected_chan[i]) get_level();

                        if(ch(selected_chan[i])get_mode()==false)
                        {
                            if(event.key.control)
                            {
                                cout << "control" << endl;
                                res = 2.55;
                            }
                            else
                            {
                                res = scroll_resolution*2.55;
                            }

thanks by advance for your answer

Athenian Hoplite

  • Newbie
  • *
  • Posts: 19
  • Nenikikamen !
    • View Profile
Re: Can't make CTRL + mouse wheel work
« Reply #1 on: May 24, 2020, 01:03:02 pm »
The sf::Event class stores its members in a union. If a sf::Event is of type sf::Event::MouseWheelMoved then it's defined member is "event.mouseWheel". To access the member "event.key" you need to have an event that is of type "sf::Event::KeyPressed" (or released).

A union is a region of memory that can be interpreted in different ways. When you access a member in a union you are requesting that memory to be given to you in that "interpretation". So although you are getting event.key the memory is actually meaningless because the memory stored in the union is for event.mouseWheel. Because of a stroke of luck it just so happens that when reading event.key the memory is layed out in such a way that it reads "true" for event.key.control.

https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1Event.php

To achieve what you want you first need to catch a sf::Event::KeyPressed and check to see if control is pressed (or not) and store that somewhere. Then in that code that you posted you need to check if your variable in which you stored if control is pressed is true.
« Last Edit: May 24, 2020, 01:07:07 pm by Athenian Hoplite »
"By will of the Athenian People be it resolved:
If anyone rises up against the people for tyranny or join in establishing the tyranny or overthrow the People of the Athenians and the democracy in Athens, whoever kills him who does these things shall be blameless." - Athenian Law 337 BC

Riton_Lafouine

  • Newbie
  • *
  • Posts: 16
    • View Profile
Re: Can't make CTRL + mouse wheel work
« Reply #2 on: May 24, 2020, 01:06:32 pm »
OK, thank you very much !!! i'll do that

***EDIT***
works like a charm and will be usefull in other places of the code also... many thanx

Regard,

RLF
« Last Edit: May 24, 2020, 05:02:11 pm by Riton_Lafouine »

 

anything