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

Author Topic: Get pressed key via Keyboard class.  (Read 3845 times)

0 Members and 1 Guest are viewing this topic.

SymegPL

  • Newbie
  • *
  • Posts: 13
    • View Profile
Get pressed key via Keyboard class.
« 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();

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Get pressed key via Keyboard class.
« Reply #1 on: March 30, 2013, 08:44:28 pm »
Have you read the doc / tutorials before asking?
Laurent Gomila - SFML developer

SymegPL

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Get pressed key via Keyboard class.
« Reply #2 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Get pressed key via Keyboard class.
« Reply #3 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.
Laurent Gomila - SFML developer

SymegPL

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Get pressed key via Keyboard class.
« Reply #4 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.
« Last Edit: March 31, 2013, 02:28:50 pm by SymegPL »

AlexAUT

  • Sr. Member
  • ****
  • Posts: 396
    • View Profile
Re: Get pressed key via Keyboard class.
« Reply #5 on: March 31, 2013, 03:12:19 pm »
You should have a look at sf::Event::TextEntered

AlexAUT

SymegPL

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Get pressed key via Keyboard class.
« Reply #6 on: March 31, 2013, 08:32:57 pm »
Yes i know. I wrote it in my last post.
This works. Thank you.