@rbxts/input-categorizer 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/out/index.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export declare const InputCategory: {
2
+ readonly KeyboardAndMouse: "KeyboardAndMouse";
3
+ readonly Gamepad: "Gamepad";
4
+ readonly Touch: "Touch";
5
+ readonly Unknown: "Unknown";
6
+ };
7
+ export declare const inputCategoryAtom: import("@rbxts/charm").Selector<"KeyboardAndMouse" | "Gamepad" | "Touch" | "Unknown">;
package/out/init.luau ADDED
@@ -0,0 +1,49 @@
1
+ -- Compiled with roblox-ts v3.0.0
2
+ local TS = _G[script]
3
+ local _charm = TS.import(script, TS.getModule(script, "@rbxts", "charm"))
4
+ local atom = _charm.atom
5
+ local computed = _charm.computed
6
+ local UserInputService = game:GetService("UserInputService")
7
+ local InputCategory = {
8
+ KeyboardAndMouse = "KeyboardAndMouse",
9
+ Gamepad = "Gamepad",
10
+ Touch = "Touch",
11
+ Unknown = "Unknown",
12
+ }
13
+ local lastInputTypeAtom = atom(UserInputService:GetLastInputType())
14
+ UserInputService.LastInputTypeChanged:Connect(lastInputTypeAtom)
15
+ local function categorizeInput(inputType)
16
+ local _value = (string.find(inputType.Name, "Gamepad"))
17
+ if _value ~= 0 and _value == _value and _value then
18
+ return InputCategory.Gamepad
19
+ else
20
+ local _value_1 = (inputType == Enum.UserInputType.Keyboard) or ((string.find(inputType.Name, "Mouse")))
21
+ if _value_1 ~= 0 and _value_1 == _value_1 and _value_1 then
22
+ return InputCategory.KeyboardAndMouse
23
+ elseif inputType == Enum.UserInputType.Touch then
24
+ return InputCategory.Touch
25
+ else
26
+ return InputCategory.Unknown
27
+ end
28
+ end
29
+ end
30
+ local inputCategoryAtom = computed(function()
31
+ local lastInputType = lastInputTypeAtom()
32
+ local category = categorizeInput(lastInputType)
33
+ if category ~= InputCategory.Unknown then
34
+ return category
35
+ end
36
+ if UserInputService.KeyboardEnabled and UserInputService.MouseEnabled then
37
+ return InputCategory.KeyboardAndMouse
38
+ elseif UserInputService.TouchEnabled then
39
+ return InputCategory.Touch
40
+ elseif UserInputService.GamepadEnabled then
41
+ return InputCategory.Gamepad
42
+ else
43
+ return InputCategory.Unknown
44
+ end
45
+ end)
46
+ return {
47
+ InputCategory = InputCategory,
48
+ inputCategoryAtom = inputCategoryAtom,
49
+ }
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@rbxts/input-categorizer",
3
+ "version": "1.0.0",
4
+ "description": "Categorize the input system that is being used.",
5
+ "main": "out/init.lua",
6
+ "scripts": {
7
+ "build": "rbxtsc",
8
+ "watch": "rbxtsc -w",
9
+ "prepublishOnly": "npm run build"
10
+ },
11
+ "keywords": [],
12
+ "author": "CriShoux",
13
+ "license": "ISC",
14
+ "type": "commonjs",
15
+ "types": "out/index.d.ts",
16
+ "files": [
17
+ "out",
18
+ "!**/*.tsbuildinfo"
19
+ ],
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "devDependencies": {
24
+ "@rbxts/compiler-types": "^3.0.0-types.0",
25
+ "@rbxts/types": "^1.0.841",
26
+ "roblox-ts": "^3.0.0",
27
+ "typescript": "^5.8.2"
28
+ },
29
+ "dependencies": {
30
+ "@rbxts/charm": "^0.10.0"
31
+ }
32
+ }