开发者

Encoding key strokes as bits in uint

开发者 https://www.devze.com 2023-03-05 02:12 出处:网络
Hey, I m trying to encode certain values that i receive from keyboard event. Basically i want to check if a certain key combination has been pressed or not, so for that i m converting the key codes in

Hey,

I m trying to encode certain values that i receive from keyboard event.

Basically i want to check if a certain key combination has been pressed or not, so for that i m converting the key codes into sequence/pattern and store it in an object and a value(function) against each code sequence.

Now i have to use four bytes and in first byte(MSB) i ve to store shift, alt, ctrl respectively and in the last(LSB) i have to store the keycode of the key pressed.

Here is the code:

private function m_encodeValue(key:String, Ctrl:Boolean = true, Alt:Boo开发者_如何学Pythonlean = true, Shift:Boolean = false):uint
        {
            var encodedValue:uint;

            encodedValue = uint(Shift) << 2 | uint(Alt) << 1 | uint(Ctrl);

            encodedValue = encodedValue | (uint(key.toUpperCase().charCodeAt(0)) << 24);

            return encodedValue;
        }


I store a sequence in an object and its corresponding value which is a function reference, then when certain key combination is pressed it is converted into sequence and check against those entries, after which Function is called.
What i was doing wrong, i was using Key_down event, i instead used Key_up, so now all the values, say ctrl + atl + v, get dispatched in the event object altogether. Whereas in Key_down case on every key press the event was firing up, making it hard to cull the keycodes i needed.

0

精彩评论

暂无评论...
验证码 换一张
取 消