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

Author Topic: Help with user-defined hotkeys  (Read 1622 times)

0 Members and 1 Guest are viewing this topic.

av8r

  • Newbie
  • *
  • Posts: 3
    • View Profile
Help with user-defined hotkeys
« on: April 25, 2020, 06:15:47 am »
Hello guys, long time reader first time poster here.

First of all, I've spent a lot of time scouring this forum, reading through Thor's documentation, and searching the web to try to solve this puzzle but I haven't nailed it yet - but if you know of a resource where this question has already been answered please let me know and I'd be happy to read it there!

I'm working on handling user input and mapping hotkeys in my current project.  I spent quite a bit of time coding a system from scratch which was working well enough for an amateur like me, but when I learned of Thor's action system I decided to scrap my old in-house work and use Thor.

Referencing the Thor documentation, it is extremely simple to hard code key mappings into the game engine - for example, I write code so that A moves left, D moves right, CTRL+ALT+SHIFT+TILDE self destructs, you name it, it's easy.  Where I've hit a road block is trying to develop a way for the user to change their hotkeys in-game.  What if my user wants move left to be the left arrow key? What if they want self destruct to be ALT+D?

It seems that I would have to pre-make a thor::Action for every single possible sf::Keyboard::Key combination that I would like to support - and this doesn't seem very clean.

For example, that would be 8 possible combinations of ctrl, alt, shift, and each supported keyboard key (over 800 possible key bindings):
1: ctrl+alt+shift+key
2: ctrl+alt+key
3: ctrl+shift+key
4: alt+shift+key
5: ctrl+key
6: alt+key
7: shift+key
8: key

Is there any better way to allow the user to decide their key mapping without having to pre-make every possible action for them to choose?  I'm sure I'm missing something elementary here.

Even mentioned on the thor::Action tutorial it says this, which is exactly what I'm trying to figure out how to do:
Quote
The Action system of Thor's Input module has been designed with the following thoughts in mind:
  • Different actions are adressed by IDs of arbitrary types (e.g. strings, enums)
  • Add, modify and remove actions at runtime to allow dynamic assignment of input events
  • Uniform treatment of one-time events (sf::Event) and realtime conditions (sf::Mouse, sf::Keyboard and sf::Joystick)
  • Possibility to link actions to a callback system

Thanks in advance for your time,
Av
« Last Edit: April 25, 2020, 07:05:33 am by av8r »

av8r

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Help with user-defined hotkeys
« Reply #1 on: April 25, 2020, 10:20:44 am »
Perhaps a simpler question that would solve this issue is this:

How do I collect user input and use it to define a new thor::Action?

If I could ask the user what hotkey they want, they press the keys, and I can collect their input to create a new thor::Action, and place that thor::Action into the ActionMap, then hotkeys could be generalized instead of having to create 800+ potential actions.

Again, thanks for your time.

SurvivalDome

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Help with user-defined hotkeys
« Reply #2 on: February 17, 2024, 10:07:27 am »
Not sure if it will help, you might have even figured it out by now, but you could use just C++ libraries to capture input, store it in a variable, then assign that variable to the hotkey

 

anything