Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get caps lock state #296

Open
deranjer opened this issue Oct 12, 2020 · 4 comments
Open

Get caps lock state #296

deranjer opened this issue Oct 12, 2020 · 4 comments
Labels

Comments

@deranjer
Copy link

Been using fyne and wanted to get the current state of the caps lock key. It appears that this may have been added in glfw 3.3: glfw/glfw#946

Has this been added to this repo as well? See the fyne ticket here: fyne-io/fyne#1391

@pwaller
Copy link
Member

pwaller commented Nov 1, 2020

From the issue you linked, the commit which closed it: glfw/glfw@0e8c4ea

See https://github.com/go-gl/glfw/search?q=GLFW_MOD_CAPS_LOCK

On the go side, it looks like:

ModCapsLock ModifierKey = C.GLFW_MOD_CAPS_LOCK

Hopefully that's enough for you to run with?

@deranjer
Copy link
Author

deranjer commented Nov 1, 2020

Per the fyne people that allows them to detect if the caps lock key is hit, but does not allow getting the current caps lock state.

@myavchik
Copy link

myavchik commented Nov 6, 2020

getKeyMods

static int getKeyMods(void)
{
int mods = 0;
if (GetKeyState(VK_SHIFT) & 0x8000)
mods |= GLFW_MOD_SHIFT;
if (GetKeyState(VK_CONTROL) & 0x8000)
mods |= GLFW_MOD_CONTROL;
if (GetKeyState(VK_MENU) & 0x8000)
mods |= GLFW_MOD_ALT;
if ((GetKeyState(VK_LWIN) | GetKeyState(VK_RWIN)) & 0x8000)
mods |= GLFW_MOD_SUPER;
if (GetKeyState(VK_CAPITAL) & 1)
mods |= GLFW_MOD_CAPS_LOCK;
if (GetKeyState(VK_NUMLOCK) & 1)
mods |= GLFW_MOD_NUM_LOCK;
return mods;
}

@pwaller
Copy link
Member

pwaller commented Nov 8, 2020

@myavchik that appears to be an implementation detail on win32 -- and doesn't amount to giving you the ability to test the key state for yourself with a glfw API. https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getkeystate

I didn't find evidence that this is in upstream. Is it? If it is, please link to it, and patches are welcome to implement the downstream bit. For now, marking external.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants