How to Send a Keypress from a UI App into BeamNG.drive

Discussion in 'Programming' started by aletoc1999, Dec 15, 2023.

  1. aletoc1999

    aletoc1999
    Expand Collapse

    Joined:
    Jul 30, 2014
    Messages:
    1
    Hello everyone,

    I’m currently developing a UI app for BeamNG.drive and am looking for a way to programmatically send a keypress from the app into the game. Specifically, I need to simulate a keypress event (such as pressing a specific key) within the game environment.

    Has anyone had experience with this, or does anyone know if it's possible through the game's Lua API or any other method? I'm open to different approaches, whether it’s directly simulating the keypress or triggering the action that is normally bound to that key.

    Any guidance, advice, or pointers to relevant documentation or examples would be greatly appreciated!

    Thank you in advance for your help!
     
  2. daniel-w

    daniel-w
    Expand Collapse
    BeamNG Team

    Joined:
    Jan 28, 2017
    Messages:
    282
    Sure, it's very simple.
    On the Javascript side of things, you will want to listen to a keypress. Once you have the key, you can send it to Lua via:
    Code:
    bngApi.engineLua("your_extension.myFunction(" + key + ")") // your_extension could be any game extension, it's just an example
    
    Hopefully this helps
     
  3. dirtwheel

    dirtwheel
    Expand Collapse
    BeamNG Team

    Joined:
    May 31, 2023
    Messages:
    75
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice