Get Physical Keyboard Layout Programmatically - winapi

Is there a way to programmatically find out what kind of keyboard a computer has (i.e. where keys are located, and what extra keys are present in which locations)?
A little error is acceptable, if the keyboard is very non-standard, but in general, the point is to construct an on-screen keyboard-like application that can dynamically draw the keyboard layout on the screen, with high accuracy.

when connected to a computer, keyboards sends "scan codes" to the operating system. on windows, scan codes are then converted into virtual keys (a hardware independent mapping of the keyboard) then to real characters.
the MapVirtualKeyEx() function of the windows API allows you to translate between scan codes, virtual keys and characters. it should also be able to tell you if a key is non-existing.
together with GetKeyboardLayout() which tells you which keybaord is active at any point in time (keyboard layout can be different for different running applications), it should allow you to build a pretty accurate map of the keyboard.
anyway, have a look at the keyboard input section of the MSDN
i will add that all keyboards have almost the same layout. although there is no way to know where a key is physically located, you can probably guess from the scan code and basic knowledge of your own keyboards.

There is no mechanism by which a keyboard can tell Windows what its physical layout looks like. Easy to see with the Windows version of an on-screen keyboard, osk.exe. It seems to be able to guess the form-factor of the machine (laptop vs desktop) but on my laptop it doesn't match the layout of the keyboard.
Use the osk.exe layout as a template so nobody can complain that yours doesn't match well.

Related

Where is loading circle on Windows stored at?

I am wondering where is, for example, that circle dotted loading animation stored, which we see on startup. What if I wanted a twerking amogus instead? IS it even possible to change that?
I'm not really looking for downloadable tools, I'm interested in deep understanding myself (I'm studying computer architecture at uni), so if you have any answer, it would make me super happy.
I changed sounds already, but it's apparently not enough for me. Also, is it possible to change a picture loaded in BIOS on the startup?
Edit: I don't mean changing the cursor
The Ring progressive animation appears to be able to be configured from the registry e.g.:
https://www.thewindowsclub.com/how-to-enable-new-progressive-ring-boot-animation-in-windows-11
Open the Registry Editor.
Navigate to SYSTEM\ControlSet001\Control key
Create a new key under the Control folder.
Name it as BootControl.
Create a new key (DWORD (32-bit.)
Rename the new key as BootProgressAnimation.
Change its value to 1.
Restart your computer.
For changing the windows splash screen see e.g. here Is it impossible to change the splash screen at runtime in uwp?
The bios "splash" image is particular to your BIOS. BIOS is basically a set of functions that are lower level than the OS and very hardware specific. So it is provided by the motherboard manufacturer. Depending on your motherboard you would have to Google on how to change it, most modern BIOS offer some option. The steps normally would be
(good to do) update the BIOS firmware
enter bios: involves pressing a key combination before booting the os, possibly del, or f1,... rtfm, or google your model
go to option for selecting the splash screen and change it
It is possible that there is also an app from the manufacturer that can do that e.g. this is for asus: https://www.techwalla.com/articles/how-to-edit-an-asus-splash-screen

Writing a Linux driver for a weird keyboard

I own a keyboard that has an anti-ghosting mode.
It is toggled on/off using Fn+ScrollLock. When on, the codes sent are a bit different. The keyboard is still legitimate HID, but, for example, all modifier keys are seen by Linux as Shift and the actual modifier key is in another field of the event.
What I am looking for is either a ready driver (should someone happen to know about one) or some introduction to writing such input drivers. I do not know much about the ecosystem (evdev, libinput, etc.) and I do not even know where to start. If possible, the same driver should work both under X11 and under Wayland.
Just for the record, the keyboard's “shop” name is Modecom Volcano Gaming. The USB ID is258a:1006 and it is apparently not annotated in usb.ids. The keyboard works perfectly fine in both modes under Windows.

How does on-screen (virtual) keyboard works in Win10

I haven't find anything relevant in Google or any Microsoft site about it so I decided to ask a question here.
Everybody knows that in Win-based OS there is a virtual keyboard. I also know that *nix based OS, have it too. So, the question is about:
HOW DOES IT WORK INSIDE?
I mean, let's have an example that I opened on screen keyboard in Windows 10. What's the actual difference between:
input via hardware keyboard: when I'm using it, like I press X button
..and using a virtual keyboard, when I press the same button
Imagine, I have an admin access to terminal/computer, is there any option to track/distinguish that in the second time I pressed button not on hardware keyboard, but on-screen (by mouse clicking) version of it?
And there are also many different software, like AutoIt (yes, it's a language, but it's relevant to this example) that emulating pressing the X button. How does they work in Win-based OS? Do they "in-common" with default on-screen keyboard and using the same driver/WinAPI or there is a difference between them?
And the second case, between:
default on-screen keyboard
compilated AutoIt script
..any other software that emulating press X button
I guess the only way to find out "how exactly button was pressed" is to check current processes list via taskmgr and find out have anything been launched or not. Or I'm totally wrong here, and missing something?
THE SCOPE
I have written a node.js script which emulates button pressing behaviour in windows app.
TL:DR business logic short => open notepad.exe and type `Hello world`
And could someone give me any advice/recommend any powershell/bat script (or any other solution) with demonstration of Get­Async­Key­State check behavior? With which I could easily check my own node.js script (not by functional of it, but by triggering press the X button event)
I found an answer for node.js case here: Detecting Key Presses Across Applications in Powershell
SendInput is the preferred method to generate user input in software. The Windows on-screen keyboard probably uses it for everything except Ctrl+Alt+Delete which I believe has some kind of special handling. The on-screen keyboard is only able to generate Ctrl+Alt+Delete in certain configurations.
Software-generated input is merged with normal hardware input in the RIT (Raw Input Thread) in the kernel.
A low-level keyboard hook can detect software-generated input.

how to Disable special keyboard keys?

I'm looking for a script or a program that runs in background and blocks special keys on my keyboard (calculator, mute, etc) I have searched a lot on this on the internet but didn't found anything useful or working for me, I tried sharpkeys but didn't detected those keys on my keyboard, key id is 173 for mute on my keyboard and I can get others IDs if I find anything to block them with IDs.
P.S. I don't know much about programming and most likely don't know what I am doing, I'm looking for basic help from anyone. thank you!
TL;DR  To disable all "special keys" you could change the Human Interface Device Access Windows service startup type from Automatic to Manual (or Disabled in case there is some other software installed that causes it to still start when set to Manual). Caution: this may break other input devices if present, such as IR remote controls, or Airplane mode radio management.
For background, those "special keys" are technically called "consumer control buttons (CCB)" (see for example Keyboard Enhancements in Windows 8 and the linked .docx - nevermind that CCBs long predate Windows 8).
The CCBs are handled by the Human Interface Device Access Windows service, as described at Human Interface Device Access:
This service provides generic access to specific functions contained within controls collections on HID (Human Interface Devices). It enables the use of predefined hot buttons on keyboards, remote controls and other multimedia devices.
If the service is stopped or disable, the buttons on USB keyboards will not function (i.e., back, forward, volume up, down, previous track, next track), nor will the volume buttons on USB speakers.
To change the Human Interface Device Access (HidServ) startup mode, navigate to My Computer / Manage / Services and Applications / Services, double-click the Human Interface Device Access in the list, and change the Startup type to Manual or Disabled.
To disable special keyboard keys via registry on Windows 10 go to HKLM:\SYSTEM\CurrentControlSet\Services\hidserv and change "Start" DWORD value to 4. Once you restart the system, special function keys should be disabled.

How to replace Windows 8 volume indicator overlay?

New to Windows 8 and 8.1 is a volume overlay that sits above all other windows, and displays for 3-5 seconds every time you press one of the special volume buttons present on many keyboards.
Please note that I am not talking about this:
But rather this:
Which appears in the top left corner of the monitor.
I would like an API or something that will disable the display of this indicator when volume buttons are pressed on the keyboard.
Does something like this exist? Programming language doesn't matter, as I can convert from whatever to whatever, but for reference I will be implementing this in C++
There is not a documented method for disabling the UI, and I'd expect that any technique for doing so would rely on potentially risky/unsupported APIs/techniques.
The UI is now provided by Microsoft to enable a standardized experience for volume control across all devices. Some applications like the Microsoft Music application expect the volume control to be present so that they appear together.
In Win 8.1, all Media handling support was moved to the SystemMediaTransportControls. An app has only a tiny bit of control over display: IsEnabled.
If possible, you might consider relying on the built in support -- as they're not likely to go away, and it's unlikely that you'll be able to control them in the manner you want.

Resources