Files
Basalt/docs/objects/Program/injectEvent.md
Robert Jelic bb1b1beb79 Basalt 1.7 Update
- New Objects (Flexbox, Graph, Treeview)
- Pluginsystem to add/remove functionality
- Reworked the entire Object system, instead of one big Object Class we have multiple classes: Object, VisualObject, ChangeableObject
- Instead of one big Frame Class we have multiple Frame Classes: BaseFrame, Frame, MovableFrame, ScrollableFrame, MonitorFrame, Flexbox
- Removed the Animation Object, and added a animation plugin instead
- Removed the Graphic Object and merged it's functionality with the image object
- Updated currently existing objects
2023-04-30 17:05:34 +02:00

37 lines
992 B
Markdown

## injectEvent
### Description
Injects an event into the program manually. For example, you could inject "w", "a", "s", and "d" for the worm game by clicking buttons.
### Parameters
1. `string` event
2. `boolean` if this is true, the injected event will be executed even if the program is paused
3. `any` ... parameters
### Returns
1. `object` The object in use
### Usage
* Inject an event by clicking a button
```lua
local basalt = require("basalt")
local mainFrame = basalt.createFrame()
local aProgram = mainFrame:addProgram():execute("rom/programs/shell.lua")
local function injectEventOnClick()
aProgram:injectEvent("char", false, "w")
end
mainFrame:addButton()
:setText("Inject W")
:onClick(injectEventOnClick)
```
In this example, a Program object is created, added to the mainFrame, and the "rom/programs/shell.lua" script is executed. A button is then added to the mainFrame that, when clicked, injects the "char" event with a parameter of "w" into the Program.