-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(extra-natives): add
REGISTER_RAW_KEYMAP
and REMAP_RAW_KEYMAP
- Loading branch information
1 parent
2ca92f1
commit acbe8f5
Showing
3 changed files
with
274 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
ns: CFX | ||
apiset: shared | ||
--- | ||
## REGISTER_RAW_KEYMAP | ||
|
||
```c | ||
void REGISTER_RAW_KEYMAP(char* keymapName, func onKeyUp, func onKeyDown, int rawKeyIndex, BOOL canBeDisabled); | ||
``` | ||
Registers a keymap that will be triggered whenever `rawKeyIndex` is pressed or released. | ||
`onKeyUp` and `onKeyDown` will not provide any arguments. | ||
```ts | ||
function onStateChange(); | ||
``` | ||
|
||
## Parameters | ||
* **keymapName**: A **unique** name that the keymap will be bound to, duplicates will result in the keymap not being registered. | ||
* **onKeyUp**: The function to run when the key is no longer being pressed. | ||
* **onKeyDown**: The function to run when the key is being pressed. | ||
* **rawKeyIndex**: The virtual key to bind this keymap to, see a list [here](https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes) | ||
* **canBeDisabled**: If calls to [DISABLE_RAW_KEY_THIS_FRAME](#_0x8BCF0014) will disable this keymap, if a keymap was disabled when the key was pressed down it will still call `onKeyUp` on release. | ||
|
||
## Examples | ||
```lua | ||
function on_key_up() | ||
print("key no longer pressed") | ||
end | ||
|
||
function on_key_down() | ||
print("key is pressed") | ||
end | ||
|
||
local KEY_E = 69 | ||
local canBeDisabled = false | ||
|
||
|
||
RegisterRawKeymap("our_keymap", on_key_up, on_key_down, KEY_E, canBeDisabled) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
--- | ||
ns: CFX | ||
apiset: client | ||
--- | ||
## REMAP_RAW_KEYMAP | ||
|
||
```c | ||
void REMAP_RAW_KEYMAP(char* keymapName, int newRawKeyIndex); | ||
``` | ||
Remaps the keymap bound to `keymapName` to `newRawKeyIndex` | ||
Virtual key codes can be found [here](https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes) | ||
## Parameters | ||
* **keymapName**: the name given to the keymap in [REGISTER_RAW_KEYMAP](#_0x49C1F6DC) | ||
* **newRawKeyIndex**: Index of raw key from keyboard. | ||
## Examples | ||
```lua | ||
function on_key_up() | ||
print("key no longer pressed") | ||
end | ||
function on_key_down() | ||
print("key is pressed") | ||
end | ||
local KEY_SPACE = 32 | ||
local canBeDisabled = false | ||
local KEY_E = 69 | ||
RegisterRawKeymap("our_keymap", on_key_up, on_key_down, KEY_SPACE, canBeDisabled) | ||
RemapRawKeymap("our_keymap", KEY_E) | ||
``` |