Recent

Author Topic: GetKeyState doesn't work on Mac?  (Read 3241 times)

hayanninja

  • New Member
  • *
  • Posts: 45
GetKeyState doesn't work on Mac?
« on: January 28, 2018, 12:15:37 pm »
In my code, I have a function that runs once per frame (even if the frame's rendering is skipped) which uses GetKeyState to determine if various keys are pressed.

On both Windows and Linux, the code runs perfectly fine. However, on Mac, it successfully detects Shift and Ctrl, but doesn't detect any of the other useful keys (for the record, these are Esc, Q, W, E, A, S, D, F, G, Space, Backspace, Enter and the arrow keys). Just on the offchance it matters (since I know Mac can be weird about things like this), I am using a Windows-style keyboard.

Bug? Different values for the keys? Something I should know that I don't?
« Last Edit: January 28, 2018, 12:30:26 pm by hayanninja »

Thaddy

  • Hero Member
  • *****
  • Posts: 14210
  • Probably until I exterminate Putin.
Re: GetKeyState doesn't work on Mac?
« Reply #1 on: January 28, 2018, 01:08:15 pm »
GetKeyState only works for available virtual keys, not for any non-virtual keys. But e.g. VK_ESCAPE works on Macs, just not the non-virtual Q,W,E,A,S,D,F,G etc.
Specialize a type, not a var.

hayanninja

  • New Member
  • *
  • Posts: 45
Re: GetKeyState doesn't work on Mac?
« Reply #2 on: January 28, 2018, 11:01:08 pm »
It doesn't seem to work for Esc either. I don't know if this might be that Esc from a Windows keyboard isn't considered the same key as Esc from a proper Mac keyboard, though.

Is there another function I can use instead that properly detects any key (virtual or not)? I only need to be able to tell "is this key currently down" vs "is this key currently up", I don't need things like eg. whether the key has been held for a while or has just now been pushed (though if such a function is available, I can probably make use of it; I just don't need it as such).

 

TinyPortal © 2005-2018