Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sleitnick/rbxts-clack
User input helper classes
https://github.com/sleitnick/rbxts-clack
roblox-ts
Last synced: 20 days ago
JSON representation
User input helper classes
- Host: GitHub
- URL: https://github.com/sleitnick/rbxts-clack
- Owner: Sleitnick
- License: mit
- Created: 2022-05-04T21:44:34.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-02-08T23:51:55.000Z (9 months ago)
- Last Synced: 2024-09-20T15:39:09.527Z (about 2 months ago)
- Topics: roblox-ts
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@rbxts/clack
- Size: 137 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Clack
User input helper classes.
## Examples
Below are examples of the input classes. The examples are not an exhaustive list of the APIs available.
### Preferred Input
The preferred input is based on the last input the user has made. Because players can change their desired input during gameplay, it is helpful to watch for these changes in order to help direct the player in the best way possible.
For instance, if there are UI elements that show the player the control schema for the game, using `observePreferredInput` can be used to dynamically change this display if the user switches between using a gamepad and using a mouse/keyboard.
```ts
const prefer = new Prefer();print(`Preferred: ${tostring(prefer.getPreferredInput())}`);
prefer.observePreferredInput((preferred) => {
print(`Preferred: ${tostring(preferred)}`);
if (preferred === Clack.InputType.MouseKeyboard) {
print("Prefer mouse and keyboard");
} else if (preferred === Clack.InputType.Touch) {
print("Prefer touch");
} else if (preferred === Clack.InputType.Gamepad) {
print("Prefer gamepad");
}
});
```### Mouse
Watch for mouse input.
```ts
const mouse = new Mouse();mouse.getButtonDownSignal(Enum.UserInputType.MouseButton1).Connect((position) => {
print("Left button down", position);
});print(mouse.getPosition());
const result = mouse.raycast(new RaycastParams());
```### Keyboard
Watch for keyboard input.
```ts
const keyboard = new Keyboard();keyboard.keyDown.Connect((keyCode) => {
print(`Key down: ${tostring(keyCode)}`);
});keyboard.keyUp.Connect((keyCode) => {
print(`Key up: ${tostring(keyCode)}`);
});print("W down", keyboard.isKeyDown(Enum.KeyCode.W));
print("CTRL+S", keyboard.isKeyComboDown(Enum.KeyCode.LeftControl, Enum.KeyCode.S));
print("Forward", keyboard.isEitherKeyDown(Enum.KeyCode.W, Enum.KeyCode.Up));
```### Gamepad
Watch for gamepad input.
```ts
const gamepad = new Gamepad();gamepad.buttonDown.Connect((button) => {
print(`Button down: ${tostring(button)}`);
});gamepad.setMotor(Enum.VibrationMotor.Large, 1);
gamepad.stopMotor(Enum.VibrationMotor.Large);
gamepad.pulseMotor(Enum.VibrationMotor.Large, 1, 0.2);const leftThumbstickPos = gamepad.getThumbstick(Enum.KeyCode.Thumbstick1);
print(`Left thumbstick position: ${tostring(leftThumbstickPos)}`);
```### Touch
Watch for touch input.
```ts
const touch = new Touch();touch.getTouchTapSignal().Connect((touchPositions, processed) => {
print("Touched");
});
```