SFML community forums

Help => Window => Topic started by: dkaip on March 12, 2010, 11:36:19 am

Title: About ctrl + Left arrow
Post by: dkaip on March 12, 2010, 11:36:19 am
I am tryin in events to take the ctrl+left arrow event. First press ctrl, then left  key.
How i can take this event?
Title: About ctrl + Left arrow
Post by: Laurent on March 12, 2010, 11:42:24 am
Code: [Select]
if (event.Type == sf::Event::KeyPressed && event.Key.Code == sf::Key::Left && event.Key.Control)
{
    ...
}
Title: About ctrl + Left arrow
Post by: dkaip on March 12, 2010, 12:25:54 pm
As i see dont work ...

error: `event' was not declared in this scope
Title: About ctrl + Left arrow
Post by: Laurent on March 12, 2010, 01:33:56 pm
Well, this is not a complete code, you have to use this line into your event loop and adapt the variables names.
Title: About ctrl + Left arrow
Post by: dkaip on March 12, 2010, 01:48:15 pm
Ok i will try.
Thank's
Jim :)

---------------------------------------------------
trying ....

if (Event.Type == sf::Event::KeyPressed && Event.Key.Code == sf::Key::LControl && Event.Key.Code == sf::Key::Left ){ ... }

dont work ...
Title: About ctrl + Left arrow
Post by: Nexus on March 12, 2010, 03:12:52 pm
Of course, the same variable can't have two values at once. Check for Control first, set a bool flag, check for Left. Reset the flag when releasing the key.

However, I think that realtime input (the sf::Input class) is more appropriate than events. How realtime input handling works is described in the tutorials.
Title: About ctrl + Left arrow
Post by: Laurent on March 12, 2010, 03:17:59 pm
Quote
if (Event.Type == sf::Event::KeyPressed && Event.Key.Code == sf::Key::LControl && Event.Key.Code == sf::Key::Left ){ ... }

dont work ...

Read my previous answer twice, this is not the code that I gave you.

Quote
Check for Control first, set a bool flag, check for Left. Reset the flag when releasing the key.

There's no need to do so, The Event::Key structure directly provides the state of modifier keys (Control, Alt, Shift).
Title: About ctrl + Left arrow
Post by: dkaip on March 12, 2010, 06:36:14 pm
Ok i will try to read and understud the structure...
Thank's
Jim