I have just managed to get an app I am working on to compile and run on Windows from Linux, and I've noticed my code for handling shift/ctrl/alt+key presses has broken.
It appears that the ev.keyboard.modifiers flag is always zero on Windows. Unless I am doing something wrong, which is always a possibility.
Line 69 is where I am testing the ev.keyboard.modifiers flag.
This is my input logic:
The modifier field is only valid for KEY_CHAR events. It hasn't been added to key press and releases yet. I think I remember seeing something on the mailing list about adding them but I can't remember right.
You already know the state of the SHIFT, CTRL, and ALT keys anyway.
This works for me on Mac and Windows.
Just skimming over your code I don't immediately see anything, but here are some thoughts:
Could you be re-initializing the keyboard a second time causing an issue?
I recall reading there is some connection between the display and keyboard. Do you have a display created?
The ev.keyboard.modifiers flag seems to be updated in the ALLEGRO_EVENT_KEY_DOWN event on Linux, at least. Looking through the Allegro source (and I'm definitely not experienced enough to know for sure) it looks like the modifiers variable is being updated in the key press function. https://github.com/liballeg/allegro5/blob/f41f49d65c89fdb214b4dd49172b5adfbf16c4ec/src/win/wkeyboard.c#L358
Thanks for the help all, I'll let you know how it goes.
UDPATE:
I have just compiled and ran the above code sample, and it does not work on my system. A snippet of the output:
shift: 0, alt: 0, ctrl: 0, command: 0, key: S shift: 0, alt: 0, ctrl: 0, command: 0, key: D shift: 0, alt: 0, ctrl: 0, command: 0, key: C shift: 0, alt: 0, ctrl: 0, command: 0, key: LSHIFT shift: 0, alt: 0, ctrl: 0, command: 0, key: C
The modifiers never change.
I may just do this manually and keep track of which modifier keys are held down myself.
Like I said, I think this was recently added. That may be why it works for Mark Oates and not for you.
The changes may be in the latest Git. If you want, you can try compiling allegro and see if the changes are there.
Just looked at the changes from 5.2.6 to 7 and yes you are absolutely correct:
https://liballeg.org/changes-5.2.html
I believe the Allegro5 libraries I got through pacman in msys were 5.2.6 so that makes sense for why it isn't working on Windows.
Thanks
Sweet.
I like the way you indent your case blocks by the way:
{"name":"613137","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/1\/9122597f3a589c446742c0ea32d0eca2.png","w":1214,"h":679,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/1\/9122597f3a589c446742c0ea32d0eca2"}
I've never seen it like that, it's very easy to read. I might actually adopt it.
Thanks Mark, I appreciate that.
Is there anyway to modify who I've given credit to for helping out? I mistakenly only gave credit to you Mark, and not Edgar, if it even means anything to you guys, hah.
, I don't need credit. It's just a way of saying thank you anyway. No real rewards for getting credit.