diff options
author | Willem Jan Palenstijn | 2013-04-18 23:35:23 +0200 |
---|---|---|
committer | Willem Jan Palenstijn | 2013-05-08 20:40:58 +0200 |
commit | 9c2341678ef4984bf92b3878295250faf980b066 (patch) | |
tree | 2fb4805e05e16b9924e80c9947e6bad723b28c4b /common/keyboard.h | |
parent | 8172d679df5148a4a32f46074b20cb6caf91844f (diff) | |
parent | a5f4ff36ffc386d48f2da49387a9655ce9295a4d (diff) | |
download | scummvm-rg350-9c2341678ef4984bf92b3878295250faf980b066.tar.gz scummvm-rg350-9c2341678ef4984bf92b3878295250faf980b066.tar.bz2 scummvm-rg350-9c2341678ef4984bf92b3878295250faf980b066.zip |
Merge branch 'master'
Diffstat (limited to 'common/keyboard.h')
-rw-r--r-- | common/keyboard.h | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/common/keyboard.h b/common/keyboard.h index bdd0a2d4af..e6db086598 100644 --- a/common/keyboard.h +++ b/common/keyboard.h @@ -224,11 +224,14 @@ enum { KBD_CTRL = 1 << 0, KBD_ALT = 1 << 1, KBD_SHIFT = 1 << 2, + KBD_NON_STICKY = (KBD_CTRL|KBD_ALT|KBD_SHIFT), // Sticky modifier flags KBD_NUM = 1 << 3, KBD_CAPS = 1 << 4, - KBD_SCRL = 1 << 5 + KBD_SCRL = 1 << 5, + KBD_STICKY = (KBD_NUM|KBD_CAPS|KBD_SCRL) + }; /** @@ -281,18 +284,27 @@ struct KeyState { /** * Check whether the non-sticky flags are *exactly* as specified by f. - * This ignors the sticky flags (KBD_NUM, KBD_CAPS, KBD_SCRL). + * This ignores the sticky flags (KBD_NUM, KBD_CAPS, KBD_SCRL). + * Sticky flags should never be passed to this function. * If you just want to check whether a modifier flag is set, just bit-and * the flag. E.g. to check whether the control key modifier is set, * you can write * if (keystate.flags & KBD_CTRL) { ... } */ bool hasFlags(byte f) const { - return f == (flags & ~(KBD_NUM|KBD_CAPS|KBD_SCRL)); + assert(!(f & KBD_STICKY)); + return f == (flags & ~KBD_STICKY); } + /** + * Check if two key states are equal. This implementation ignores the state + * of the sticky flags (caps lock, num lock, scroll lock) completely. This + * functionality is currently only used by the keymapper. + */ bool operator==(const KeyState &x) const { - return keycode == x.keycode && ascii == x.ascii && flags == x.flags; + // Intentionally ignore ASCII, as the keycode and non-sticky flag + // combination should suffice. + return keycode == x.keycode && hasFlags(x.flags & ~KBD_STICKY); } }; |