Skip to content

Commit 8f99366

Browse files
committed
Handle ctrl-key
1 parent e4be725 commit 8f99366

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

src/Engine/Game.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,16 @@ void Game::run()
209209
break;
210210
}
211211
break;
212+
case SDL_KEYDOWN:
213+
case SDL_KEYUP:
214+
if (Options::getBool("strafe") && (_event.type == SDL_KEYDOWN) && (&_event)->key.keysym.sym == SDLK_LCTRL)
215+
{
216+
setCtrlKeyDown(true);
217+
}
218+
if ((_event.type == SDL_KEYUP) && (&_event)->key.keysym.sym == SDLK_LCTRL)
219+
{
220+
setCtrlKeyDown(false);
221+
}
212222
case SDL_MOUSEMOTION:
213223
case SDL_MOUSEBUTTONDOWN:
214224
case SDL_MOUSEBUTTONUP:
@@ -480,4 +490,21 @@ void Game::setMouseActive(bool active)
480490
_cursor->setVisible(active);
481491
}
482492

493+
bool Game::_ctrlKeyDown;
494+
/**
495+
* Sets whether the control key is down
496+
*/
497+
void Game::setCtrlKeyDown(bool ctrlKey)
498+
{
499+
_ctrlKeyDown = ctrlKey;
500+
}
501+
502+
/**
503+
* Returns whether the control key is down
504+
*/
505+
bool Game::getCtrlKeyDown()
506+
{
507+
return _ctrlKeyDown;
508+
}
509+
483510
}

src/Engine/Game.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class Game
5555
bool _quit, _init;
5656
FpsCounter *_fpsCounter;
5757
bool _mouseActive;
58+
static bool _ctrlKeyDown; // Used so player can indicate strafing movement.
5859
public:
5960
/// Creates a new game and initializes SDL.
6061
Game(const std::string &title);
@@ -98,6 +99,10 @@ class Game
9899
void loadRuleset();
99100
/// Sets whether the mouse cursor is activated.
100101
void setMouseActive(bool active);
102+
/// Sets whether the Ctrl Key is down
103+
static void setCtrlKeyDown(bool ctrlKey);
104+
/// Returns whether the control key is down
105+
static bool getCtrlKeyDown();
101106
};
102107

103108
}

0 commit comments

Comments
 (0)