Skip to content
/ multikb Public

Simple windows functions to read seperate input from multiple keyboards

Notifications You must be signed in to change notification settings

idk-v1/multikb

Repository files navigation

MultiKB

Simple windows functions to read seperate input from multiple keyboards

How this works:
A hidden window is created that recieves input messages.
This program registers for raw input messages, and will recieve them as long as any window owned by this program is active.

The multiKB_Update function runs a message loop to get key changed messages, then sets the last key state to the current key state for comparing later.

Usage:

Create a KBManager struct that will store all of the keyboard data.
Call multiKB_Setup() to setup internal things and allocate memory.

Using toggle keys like capslock and numlock is on by default.
Set the useToggle member in KBManager to false to disable this.
If useToggle is false they will work like any other key and only be on while being held.

Call multiKB_Update() to check for key state changes.

Helper functions

multiKB_Key() gets the current key state
multiKB_KeyLast() gets the last key state
multiKB_KeyPress() returns true if the current state is on and the last state was off
multiKB_KeyRelease() returns true if the current state is off and the last state was on

To read the key state without these:
0th bit - Raw State
1st bit - Current State
2nd bit - Last State

Call multiKB_Setup() to release allocated memory when you are done with the program.

C++ Wrapper:

create a KBManagerPP class
update() to check for key state changes

key() gets the current key state
keyLast() gets the last key state
keyPress() returns true if the current state is on and the last state was off
keyRelease() returns true if the current state is off and the last state was on