SFML community forums

Help => Window => Topic started by: SymegPL on March 30, 2013, 08:18:53 pm

Title: Get pressed key via Keyboard class.
Post by: SymegPL on March 30, 2013, 08:18:53 pm
Is it possible to get pressed key on keyboard via Keyboard class? Something similar to OnKeyboardKeyPressed event.
Example (C#):
Keyboard.Key key = Keyboard.GetLastKey();
Title: Re: Get pressed key via Keyboard class.
Post by: Laurent on March 30, 2013, 08:44:28 pm
Have you read the doc / tutorials before asking?
Title: Re: Get pressed key via Keyboard class.
Post by: SymegPL on March 30, 2013, 11:29:02 pm
Yes. I saw method which allows to check if specified key is pressed. I need last pressed key.
I stayed longer on this sentence:
Quote
This tutorial explains how to access global inputs: keyboard, mouse and joysticks. This must not be confused with events: real-time inputs allow you to query the global state of keyboard, mouse and joysticks at any time ("is this button currently pressed?", "where is the mouse?") while events notify you when something happens ("this button was pressed", "the mouse has moved").
and I believe this is possible only with events?

Sorry for my bad english btw.
Title: Re: Get pressed key via Keyboard class.
Post by: Laurent on March 31, 2013, 09:37:49 am
If you want to get the last pressed key, then yes, you must store it yourself in a variable, using events.
Title: Re: Get pressed key via Keyboard class.
Post by: SymegPL on March 31, 2013, 12:50:28 pm
Ok, thank you. I've got another question.
How to get char from passing Key code and is shift pressed, alt pressed?
Example:
char c = ConvertToChar(Keyboard.Key.A, true, true);
//KeyCode, isShift, isAlt
in PL should return Ą
Is it possible only with MapVirtualKey WinAPI function?

@EDIT I will check TextEntered event.
Title: Re: Get pressed key via Keyboard class.
Post by: AlexAUT on March 31, 2013, 03:12:19 pm
You should have a look at sf::Event::TextEntered

AlexAUT
Title: Re: Get pressed key via Keyboard class.
Post by: SymegPL on March 31, 2013, 08:32:57 pm
Yes i know. I wrote it in my last post.
This works. Thank you.