jonaskohl / CapsLockIndicator

A small utility that indicates the state of the Num lock, Caps lock and Scroll lock key.
https://cli.jonaskohl.de/
Apache License 2.0
336 stars 41 forks source link

Keyboard layout indicator #103

Closed oleg-sgh closed 1 year ago

oleg-sgh commented 2 years ago

Hello. Is it possible to add a keyboard layout indicator when enabling a layout other than the default one?

jonaskohl commented 2 years ago

Doesn't Windows already come with an input indicator?

oleg-sgh commented 2 years ago

Doesn't Windows already come with an input indicator?

It is very small and not noticeable. It would be nice if there would be the same notification with a different layout. I use the on-screen notification mode when Num Lock, Caps Lock, and Scroll Lock are on.

jonaskohl commented 2 years ago

I have taken another look at it and implementing this seems to be a huge undertaking, as there is a) no managed function to retrieve the current keyboard layout, so p/invoking would be necessary and b) the keyboard layout is set on a per-thread basis, thus making it really difficult to retrieve the keyboard layout for any given process.

oleg-sgh commented 2 years ago

I now have a homemade app on AutoHotkey. A narrow red stripe above the taskbar if a different layout. Maybe something will help.

Color1 := "0x0C0BC0", Color2 := "f00000",  x := 0, y := 718, w := 1400, h := 6
loop
{
  If (InputLayout() = "English")
  {
    Gui, +AlwaysOnTop -Caption +ToolWindow +LastFound
    Gui, Color, % Color2
    Gui, Show, x%x% y%y% w%w% h%h% NA
  }
  else
    Gui Destroy
    sleep, 50
}
InputLayout()
{
  ThreadID := DllCall("GetWindowThreadProcessId", "Int", WinExist("A"), "Int", 0)
  HKL := DllCall("GetKeyboardLayout", "uint", ThreadID, "UShort")
  VarSetCapacity(sKbd, 260, 0)
  DllCall("GetLocaleInfo", "uint", HKL
    , "uint", 0x1001
    , "str",  sKbd
    , "uint", 260)
  Return sKbd
}
qvlm_This_and_next_line_added_by_Ahk2Exe:
Exit
jonaskohl commented 2 years ago

The key components seem to be GetWindowThreadProcessId, GetKeyboardLayout and GetLocaleInfo. I will put this on my backlog, although with low priority. Meanwhile, this will be available for anyone who is interested; pull requests are welcome!

oleg-sgh commented 2 years ago

Thanks

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.