Skip to content

NightfallCT/KCD2-KeyboardSim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nightfall's KCD2 Keyboard API

Nightfall's KCD2 Keyboard API is a lightweight integration tool for Kingdom Come: Deliverance 2. It bridges the gap between the game's internal scripting engine and the Windows Operating System. By monitoring the game's output log (kcd.log) in real-time, it intercepts specific strings and translates them into simulated hardware-level keyboard and mouse inputs.

Built as a proxy DLL, it seamlessly loads with the game while maintaining original functionality, allowing modders and Lua script developers to trigger physical OS keystrokes and mouse clicks directly from in-game events.

Installation Instructions

  1. Download or compile the mod. You should have a file named KCD2-KeyboardSim.dll.
  2. Rename the compiled KCD2-KeyboardSim.dll file to WhGdk.dll.
  3. Navigate to your game's binary folder: ...\KingdomComeDeliverance2\Bin\Win64MasterMasterSteamPGO
  4. Locate the original WhGdk.dll and rename it to WhGdk_orig.dll.
  5. Drag and drop your newly renamed modded WhGdk.dll into that same folder.
  6. Launch the game. A console window will initialize automatically confirming the simulator has loaded.

Main Features

  • Proxy Loading — Safely hooks into the game's boot process by forwarding GetWhGdkWrapper to the original DLL. The game runs normally without missing critical exports.
  • Real-Time Log Tailing — Continuously monitors and reads updates from kcd.log (looking backwards up to 16 characters for new changes) without locking the file.
  • Hardware-Level Input Simulation — Utilizes Windows SendInput to generate authentic keyboard and mouse events with built-in timing delays (50ms press, 100ms release) to ensure the game engine registers the inputs accurately.
  • Console Debugging — Opens an external console window alongside the game to display target paths, initial file content, and debug messaging. (If build in Debug Mode)

How to Use

Once installed, any mod, Lua script, or game event that prints specific trigger phrases to kcd.log will cause the mod to simulate that key press.

If your custom Lua script executes System.LogAlways("Press MLeft"), the mod will detect the update in kcd.log and simulate a physical Left Mouse Button click.

If you want to make bigger scripts, you can use my lua executor to write larger multiline scripts for the game (https://www.nexusmods.com/kingdomcomedeliverance2/mods/3111).

Here is an example, which will press the left mouse buttom, as soon as an entity is within 1 meter of the player:

proximityLoopRunning = true

function CheckNearby()
    if not proximityLoopRunning then return end

    local pos = player:GetPos()
    local radius = 2
    for _, e in pairs(System.GetEntities(pos, radius) or {}) do
        if e.id ~= player.id and e.soul then
            local ep = e:GetPos()
            local d2 = (ep.x - pos.x)^2 + (ep.y - pos.y)^2 + (ep.z - pos.z)^2
            if d2 <= radius * radius then
                System.LogAlways("Press MLeft")
                break
            end
        end
    end
    Script.SetTimer(200, CheckNearby)
end

CheckNearby()

Supported Command Strings: Simply print the exact string via System.LogAlways('') to trigger the corresponding key/mouse action:

  • Mouse: Press MLeft, Press MRight, Press MMiddle, Press MX1, Press MX2
  • Alphabet: Press A through Press Z
  • Numbers: Press 0 through Press 9
  • Special Keys: Press SPACE, Press ENTER, Press SHIFT, Press TAB, Press CTRL, Press ALT, Press ESC
  • Arrows: Press UP, Press DOWN, Press LEFT, Press RIGHT

⚠️ Important Safety Notes

  • System-Wide Inputs: Because this mod uses Windows SendInput, the key presses and mouse clicks are sent to the OS itself, not just the game window. If you ALT+TAB out of KCD2 while a script is spamming log commands, it will click and type on your desktop or other applications. Use with caution.
  • File I/O Performance: The mod reads kcd.log on a 10ms loop. While extremely fast, generating excessively massive log files via other mods may impact the tailing performance.
  • Compatibility Issues: Ensure no other mods are trying to proxy the exact same WhGdk.dll. If you are using other proxy mods, you may need to chain your DLLs.

Support

If you encounter bugs, have feature suggestions, or need help integrating this into your own Lua scripts, message me on Discord: NightfallCT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors