Skip to Content

Split Loaf Introduction

A Keyboard Rerouter For Windows
2 December 2025 by
Split Loaf Introduction
All Things Toasty Software Ltd, Austin Welsh-Graham
| No comments yet

The Split Loaf is a Windows based utility for keyboard redirection to allow the mouse and keyboard to be used separately. The aim is that it does this by first selecting a target window using a function key, currently set to F8. This gets the ID of the current active window and sets it to the target. Then once the user is ready to lock their keyboard so that it can act independently of the mouse they can press another function (currently F6) this then means that no matter where the mouse is, or what its doing, any use of the keyboard goes straight to the target window instead and at the end you can press a final function key (currently F7) to set link the keyboard and mouse together.


Although it is still in very early development, a sort of working solution has been made however it is very temperamental and doesn't work across all applications. My current idea as to why is that with apps like Google, there isn't an explicit place for text to go, if you pass keyboard input to Google it doesn't know whether to put this in the search bar, or one of the multiple text boxes that may be on the page, alternatively with apps like notepad, there is a clear place for it to be put so it can work almost perfectly.


There are currently 2 different possible methods to send the character over. The first is:

 if (locked && (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN)) {
if (targetWindow) {
HWND prev = GetForegroundWindow();
SetForegroundWindow(targetWindow);
Sleep(1);

SendVirtualKeyToTarget(kbd->vkCode);


if (prev) {

SetForegroundWindow(prev);
}

return 1; // swallow original

}
}

and the second is:

if (locked && (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN)) {
if (targetWindow) {

// Send key directly to the target window WITHOUT switching focus

PostMessage(targetWindow, WM_KEYDOWN, kbd->vkCode, 0);

// swallow original key

return 1;
}
}

if (locked && (wParam == WM_KEYUP || wParam == WM_SYSKEYUP)) {

if (targetWindow) {
PostMessage(targetWindow, WM_KEYUP, kbd->vkCode, 0);
return 1;
}
}

The initial if statement is the same across them, it checks to see if the keyboard is in locked mode so that the keyboard should be rerouted and then also checks to see if a key has been pressed down. After this it checks to make sure a targetwindow has actually been set, after this they differ.


The first option grabs the current active window, then switches it to the target window and sleeps for a millisecond. after this it then sends the key pressed to the target window  using the function below.

void SendVirtualKeyToTarget(DWORD vkCode) {
INPUT in[2] = {0};

// Key down
in[0].type = INPUT_KEYBOARD;
in[0].ki.wVk = vkCode;
in[0].ki.dwFlags = 0;

// Key up
in[1].type = INPUT_KEYBOARD;
in[1].ki.wVk = vkCode;
in[1].ki.dwFlags = KEYEVENTF_KEYUP;

SendInput(2, in, sizeof(INPUT));
}

This then uses the SendInput function to actually send the key pressed to the targetwindow.


The second method is a simpler one as it just uses the PostMessage function to instead send the key pressed, this means that the computer isn't manually switching between the active window however it means that its supported by less apps as in testing apps like CLion or Google Chrome didn't work potentially due to some flaw in the code or due to the function itself.

The first method does work for CLion (however not Google Chrome) but is a lot buggier and and doubles the characters typed potentially due to how the Key Down and Key Up are handled.


A few key additions that will need to be worked on for this project are:

  • Modifier key support (Shift, Ctrl, Alt, etc.,)`
  • Better error handling and target window validation.
  • Consistent use across different applications and targets.
  • Somewhat decent performance (hopefully).
Split Loaf Introduction
All Things Toasty Software Ltd, Austin Welsh-Graham 2 December 2025
Share this post
Archive
Sign in to leave a comment