mirror of
https://github.com/love2d/love.git
synced 2026-08-15 15:51:12 +02:00
Added love.keyboard.setKeyRepeat and love.keyboard.hasKeyRepeat (resolves issue #717)
This commit is contained in:
@@ -97,6 +97,8 @@ Message *Event::convert(const SDL_Event &e) const
|
|||||||
{
|
{
|
||||||
Message *msg = NULL;
|
Message *msg = NULL;
|
||||||
|
|
||||||
|
love::keyboard::Keyboard *kb = 0;
|
||||||
|
|
||||||
love::keyboard::Keyboard::Key key;
|
love::keyboard::Keyboard::Key key;
|
||||||
love::mouse::Mouse::Button button;
|
love::mouse::Mouse::Button button;
|
||||||
Variant *arg1, *arg2, *arg3;
|
Variant *arg1, *arg2, *arg3;
|
||||||
@@ -106,6 +108,13 @@ Message *Event::convert(const SDL_Event &e) const
|
|||||||
switch (e.type)
|
switch (e.type)
|
||||||
{
|
{
|
||||||
case SDL_KEYDOWN:
|
case SDL_KEYDOWN:
|
||||||
|
if (e.key.repeat)
|
||||||
|
{
|
||||||
|
kb = (love::keyboard::Keyboard *) Module::findInstance("love.keyboard.");
|
||||||
|
if (kb && !kb->hasKeyRepeat())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
keyit = keys.find(e.key.keysym.sym);
|
keyit = keys.find(e.key.keysym.sym);
|
||||||
if (keyit != keys.end())
|
if (keyit != keys.end())
|
||||||
key = keyit->second;
|
key = keyit->second;
|
||||||
|
|||||||
@@ -235,6 +235,18 @@ public:
|
|||||||
|
|
||||||
virtual ~Keyboard() {}
|
virtual ~Keyboard() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets whether repeat keypress events should be sent if a key is held down.
|
||||||
|
* Does not affect text input events.
|
||||||
|
* @param enable Whether to send repeat key press events.
|
||||||
|
**/
|
||||||
|
virtual void setKeyRepeat(bool enable) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets whether repeat keypress events will be sent if a key is held down.
|
||||||
|
**/
|
||||||
|
virtual bool hasKeyRepeat() const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether a certain key is down or not.
|
* Checks whether a certain key is down or not.
|
||||||
* @param key A key identifier.
|
* @param key A key identifier.
|
||||||
|
|||||||
@@ -29,11 +29,26 @@ namespace keyboard
|
|||||||
namespace sdl
|
namespace sdl
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Keyboard::Keyboard()
|
||||||
|
: key_repeat(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
const char *Keyboard::getName() const
|
const char *Keyboard::getName() const
|
||||||
{
|
{
|
||||||
return "love.keyboard.sdl";
|
return "love.keyboard.sdl";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Keyboard::setKeyRepeat(bool enable)
|
||||||
|
{
|
||||||
|
key_repeat = enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Keyboard::hasKeyRepeat() const
|
||||||
|
{
|
||||||
|
return key_repeat;
|
||||||
|
}
|
||||||
|
|
||||||
bool Keyboard::isDown(Key *keylist) const
|
bool Keyboard::isDown(Key *keylist) const
|
||||||
{
|
{
|
||||||
const Uint8 *keystate = SDL_GetKeyboardState(0);
|
const Uint8 *keystate = SDL_GetKeyboardState(0);
|
||||||
|
|||||||
@@ -42,12 +42,19 @@ class Keyboard : public love::keyboard::Keyboard
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
Keyboard();
|
||||||
|
|
||||||
// Implements Module.
|
// Implements Module.
|
||||||
const char *getName() const;
|
const char *getName() const;
|
||||||
|
|
||||||
|
void setKeyRepeat(bool enable);
|
||||||
|
bool hasKeyRepeat() const;
|
||||||
bool isDown(Key *keylist) const;
|
bool isDown(Key *keylist) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
bool key_repeat;
|
||||||
|
|
||||||
static std::map<Key, SDL_Keycode> createKeyMap();
|
static std::map<Key, SDL_Keycode> createKeyMap();
|
||||||
static std::map<Key, SDL_Keycode> keys;
|
static std::map<Key, SDL_Keycode> keys;
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,19 @@ namespace love
|
|||||||
namespace keyboard
|
namespace keyboard
|
||||||
{
|
{
|
||||||
|
|
||||||
static Keyboard *instance;
|
static Keyboard *instance = 0;
|
||||||
|
|
||||||
|
int w_setKeyRepeat(lua_State *L)
|
||||||
|
{
|
||||||
|
instance->setKeyRepeat(luax_toboolean(L, 1));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int w_hasKeyRepeat(lua_State *L)
|
||||||
|
{
|
||||||
|
luax_pushboolean(L, instance->hasKeyRepeat());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int w_isDown(lua_State *L)
|
int w_isDown(lua_State *L)
|
||||||
{
|
{
|
||||||
@@ -53,6 +65,8 @@ int w_isDown(lua_State *L)
|
|||||||
// List of functions to wrap.
|
// List of functions to wrap.
|
||||||
static const luaL_Reg functions[] =
|
static const luaL_Reg functions[] =
|
||||||
{
|
{
|
||||||
|
{ "setKeyRepeat", w_setKeyRepeat },
|
||||||
|
{ "hasKeyRepeat", w_hasKeyRepeat },
|
||||||
{ "isDown", w_isDown },
|
{ "isDown", w_isDown },
|
||||||
{ 0, 0 }
|
{ 0, 0 }
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ namespace love
|
|||||||
namespace keyboard
|
namespace keyboard
|
||||||
{
|
{
|
||||||
|
|
||||||
|
int w_setKeyRepeat(lua_State *L);
|
||||||
|
int w_hasKeyRepeat(lua_State *L);
|
||||||
int w_isDown(lua_State *L);
|
int w_isDown(lua_State *L);
|
||||||
extern "C" LOVE_EXPORT int luaopen_love_keyboard(lua_State *L);
|
extern "C" LOVE_EXPORT int luaopen_love_keyboard(lua_State *L);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user