요약
속성
MouseIcon:ContentId |
메서드
GamepadSupports(gamepadNum: Enum.UserInputType,gamepadKeyCode: Enum.KeyCode):boolean |
GetGamepadConnected(gamepadNum: Enum.UserInputType):boolean |
GetGamepadState(gamepadNum: Enum.UserInputType):{InputObject} |
GetImageForKeyCode(keyCode: Enum.KeyCode):ContentId |
GetStringForKeyCode(keyCode: Enum.KeyCode,format: Enum.KeyCodeStringFormat):string |
GetSupportedGamepadKeyCodes(gamepadNum: Enum.UserInputType):{any} |
GetUserCFrame(type: Enum.UserCFrame):CFrame |
IsGamepadButtonDown(gamepadNum: Enum.UserInputType,gamepadKeyCode: Enum.KeyCode):boolean |
IsKeyDown(keyCode: Enum.KeyCode):boolean |
IsMouseButtonPressed(mouseButton: Enum.UserInputType):boolean |
IsNavigationGamepad(gamepadEnum: Enum.UserInputType):boolean |
SetNavigationGamepad(gamepadEnum: Enum.UserInputType,enabled: boolean):() |
이벤트
상속된 멤버
API 참조
속성
AccelerometerEnabled
코드 샘플
가속도계를 사용하여 공 이동하기
local Workspace = game:GetService("Workspace")
local UserInputService = game:GetService("UserInputService")
local ball = script.Parent:WaitForChild("Ball")
local mass = ball:GetMass()
local gravityForce = ball:WaitForChild("GravityForce")
local function moveBall(gravity)
gravityForce.Force = gravity.Position * Workspace.Gravity * mass
end
if UserInputService.AccelerometerEnabled then
UserInputService.DeviceGravityChanged:Connect(moveBall)
endModalEnabled
MouseIcon
UserInputService.MouseIcon:ContentId
코드 샘플
커스텀 마우스 아이콘
local UserInputService = game:GetService("UserInputService")
-- 커서를 이전 설정으로 복원하기 위해서는 변수를 통해 저장해야 합니다.
local savedCursor = nil
local function setTemporaryCursor(cursor: string)
-- 현재 저장되지 않은 경우에만 저장된 커서를 업데이트합니다.
if not savedCursor then
savedCursor = UserInputService.MouseIcon
end
UserInputService.MouseIcon = cursor
end
local function clearTemporaryCursor()
-- 저장된 커서가 있을 경우에만 마우스 커서를 복원합니다.
if savedCursor then
UserInputService.MouseIcon = savedCursor
-- 같은 커서를 두 번 복원하지 않습니다 (다른 스크립트를 덮어쓸 수 있습니다).
savedCursor = nil
end
end
setTemporaryCursor("http://www.roblox.com/asset?id=163023520")
print(UserInputService.MouseIcon)
clearTemporaryCursor()MouseIconContent
코드 샘플
커스텀 마우스 아이콘
local UserInputService = game:GetService("UserInputService")
-- 커서를 이전 설정으로 복원하기 위해서는 변수를 통해 저장해야 합니다.
local savedCursor = nil
local function setTemporaryCursor(cursor: string)
-- 현재 저장되지 않은 경우에만 저장된 커서를 업데이트합니다.
if not savedCursor then
savedCursor = UserInputService.MouseIcon
end
UserInputService.MouseIcon = cursor
end
local function clearTemporaryCursor()
-- 저장된 커서가 있을 경우에만 마우스 커서를 복원합니다.
if savedCursor then
UserInputService.MouseIcon = savedCursor
-- 같은 커서를 두 번 복원하지 않습니다 (다른 스크립트를 덮어쓸 수 있습니다).
savedCursor = nil
end
end
setTemporaryCursor("http://www.roblox.com/asset?id=163023520")
print(UserInputService.MouseIcon)
clearTemporaryCursor()PreferredInput
코드 샘플
선호 입력 감지
local UserInputService = game:GetService("UserInputService")
local function preferredInputChanged()
local preferredInput = UserInputService.PreferredInput
if preferredInput == Enum.PreferredInput.Touch then
-- 플레이어는 다른 입력 유형이 사용 가능/연결되지 않은 터치 지원 장치에 있습니다.
print("Touch")
elseif preferredInput == Enum.PreferredInput.Gamepad then
-- 플레이어는 게임패드를 연결했거나 최근에 상호작용했습니다.
print("Gamepad")
elseif preferredInput == Enum.PreferredInput.KeyboardAndMouse then
-- 플레이어는 키보드 또는 마우스를 연결했거나 최근에 상호작용했습니다.
print("KeyboardAndMouse")
end
end
preferredInputChanged()
UserInputService:GetPropertyChangedSignal("PreferredInput"):Connect(function()
preferredInputChanged()
end)UserHeadCFrame
VREnabled
메서드
GamepadSupports
UserInputService:GamepadSupports(
매개 변수
반환
GetDeviceAcceleration
코드 샘플
출력 장치 가속화
local UserInputService = game:GetService("UserInputService")
if UserInputService.AccelerometerEnabled then
local acceleration = UserInputService:GetDeviceAcceleration().Position
print(acceleration)
else
warn("장치에 활성화된 가속도가 없기 때문에 장치 가속도를 가져올 수 없습니다!")
endGetDeviceGravity
코드 샘플
자이로스코프를 이용한 물체 이동
local UserInputService = game:GetService("UserInputService")
local bubble = script.Parent:WaitForChild("Bubble")
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = CFrame.new(0, 20, 0) * CFrame.Angles(-math.pi / 2, 0, 0)
if UserInputService.GyroscopeEnabled then
-- 자이로스코프가 변화를 감지할 때 이벤트 바인딩
UserInputService.DeviceGravityChanged:Connect(function(accel)
-- 자이로스코프 데이터를 기반으로 세상에서 버블을 이동
bubble.Position = Vector3.new(-8 * accel.Position.X, 1.8, -8 * accel.Position.Z)
end)
endGetDeviceRotation
GetGamepadConnected
매개 변수
반환
GetGamepadState
매개 변수
반환
GetImageForKeyCode
매개 변수
반환
ContentId
코드 샘플
UserInputService - KeyCode에 대한 이미지 가져오기
local UserInputService = game:GetService("UserInputService")
local imageLabel = script.Parent
local key = Enum.KeyCode.ButtonA
local mappedIconImage = UserInputService:GetImageForKeyCode(key)
imageLabel.Image = mappedIconImageGetLastInputType
코드 샘플
마지막 입력 유형 감지
local UserInputService = game:GetService("UserInputService")
if UserInputService:GetLastInputType() == Enum.UserInputType.Keyboard then
print("가장 최근 입력은 키보드입니다!")
endGetMouseButtonsPressed
반환
코드 샘플
눌린 마우스 버튼 확인
local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
-- 눌린 마우스 버튼의 배열을 반환합니다
local buttonsPressed = UserInputService:GetMouseButtonsPressed()
local m1, m2 = false, false
for _, button in buttonsPressed do
if button.UserInputType == Enum.UserInputType.MouseButton1 then
print("MouseButton1이 눌렸습니다!")
m1 = true
end
if button.UserInputType == Enum.UserInputType.MouseButton2 then
print("MouseButton2가 눌렸습니다!")
m2 = true
end
if m1 and m2 then
print("두 마우스 버튼이 모두 눌렸습니다!")
end
end
end)GetMouseDelta
반환
코드 샘플
마우스 델타 가져오기
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
local function onRenderStep()
local delta = UserInputService:GetMouseDelta()
if delta ~= Vector2.new(0, 0) then
print("마우스가 이동했습니다", delta, "마지막 단계 이후")
end
end
RunService:BindToRenderStep("MeasureMouseMovement", Enum.RenderPriority.Input.Value, onRenderStep)GetStringForKeyCode
매개 변수
| 기본값: "Default" |
반환
GetSupportedGamepadKeyCodes
매개 변수
반환
GetUserCFrame
IsGamepadButtonDown
UserInputService:IsGamepadButtonDown(
매개 변수
반환
IsMouseButtonPressed
매개 변수
반환
매개 변수
반환
RecenterUserHeadCFrame
UserInputService:RecenterUserHeadCFrame():()
반환
()
매개 변수
반환
()
이벤트
DeviceAccelerationChanged
매개 변수
코드 샘플
가속도계를 사용하여 플레이어 제어하기
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local SENSITIVITY = 0.2
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local ready = true
local function changeAcceleration(acceleration)
if ready then
ready = false
local accel = acceleration.Position
if accel.Y >= SENSITIVITY then
humanoid.Jump = true
end
if accel.Z <= -SENSITIVITY then
humanoid:Move(Vector3.new(-1, 0, 0))
end
if accel.Z >= SENSITIVITY then
humanoid:Move(Vector3.new(1, 0, 0))
end
if accel.X <= -SENSITIVITY then
humanoid:Move(Vector3.new(0, 0, 1))
end
if accel.X >= SENSITIVITY then
humanoid:Move(Vector3.new(0, 0, -1))
end
task.wait(1)
ready = true
end
end
if UserInputService.AccelerometerEnabled then
UserInputService.DeviceAccelerationChanged:Connect(changeAcceleration)
endDeviceGravityChanged
매개 변수
코드 샘플
가속도계를 사용하여 공 이동하기
local Workspace = game:GetService("Workspace")
local UserInputService = game:GetService("UserInputService")
local ball = script.Parent:WaitForChild("Ball")
local mass = ball:GetMass()
local gravityForce = ball:WaitForChild("GravityForce")
local function moveBall(gravity)
gravityForce.Force = gravity.Position * Workspace.Gravity * mass
end
if UserInputService.AccelerometerEnabled then
UserInputService.DeviceGravityChanged:Connect(moveBall)
endDeviceRotationChanged
매개 변수
GamepadConnected
매개 변수
GamepadDisconnected
매개 변수
InputBegan
매개 변수
InputChanged
매개 변수
InputEnded
매개 변수
JumpRequest
코드 샘플
기본 점프 비활성화
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
local processJumpRequest = false
local COOLDOWN_TIME = 0.5
local function jumpRequest()
if processJumpRequest == false then
processJumpRequest = true
-- 사용자 정의 점프 요청 처리
print("점프 요청됨!")
-- 쿨타임 후 디바운스 변수 리셋
task.wait(COOLDOWN_TIME)
processJumpRequest = false
end
end
UserInputService.JumpRequest:Connect(jumpRequest)LastInputTypeChanged
매개 변수
PointerAction
TextBoxFocused
매개 변수
코드 샘플
포커스된 텍스트 박스 수정
local UserInputService = game:GetService("UserInputService")
local function textBoxFocused(textBox)
textBox.BackgroundTransparency = 0
end
local function textBoxFocusReleased(textBox)
textBox.BackgroundTransparency = 0.5
end
UserInputService.TextBoxFocused:Connect(textBoxFocused)
UserInputService.TextBoxFocusReleased:Connect(textBoxFocusReleased)TextBoxFocusReleased
매개 변수
코드 샘플
포커스된 텍스트 박스 수정
local UserInputService = game:GetService("UserInputService")
local function textBoxFocused(textBox)
textBox.BackgroundTransparency = 0
end
local function textBoxFocusReleased(textBox)
textBox.BackgroundTransparency = 0.5
end
UserInputService.TextBoxFocused:Connect(textBoxFocused)
UserInputService.TextBoxFocusReleased:Connect(textBoxFocusReleased)TouchDrag
UserInputService.TouchDrag(
매개 변수
TouchEnded
매개 변수
TouchLongPress
UserInputService.TouchLongPress(
매개 변수
TouchMoved
매개 변수
TouchPan
UserInputService.TouchPan(
touchPositions:{any}, totalTranslation:Vector2, velocity:Vector2, state:Enum.UserInputState, gameProcessedEvent:boolean
매개 변수
TouchPinch
UserInputService.TouchPinch(
touchPositions:{any}, scale:number, velocity:number, state:Enum.UserInputState, gameProcessedEvent:boolean
매개 변수
TouchRotate
UserInputService.TouchRotate(
touchPositions:{any}, rotation:number, velocity:number, state:Enum.UserInputState, gameProcessedEvent:boolean
매개 변수
TouchStarted
매개 변수
TouchSwipe
UserInputService.TouchSwipe(
매개 변수
TouchTap
TouchTapInWorld
UserCFrameChanged
WindowFocusReleased
코드 샘플
창 포커스 이탈 스크립트 (LocalScript)
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local awayEvent = ReplicatedStorage:WaitForChild("AwayEvent")
local function focusGained()
awayEvent:FireServer(false)
end
local function focusReleased()
awayEvent:FireServer(true)
end
UserInputService.WindowFocused:Connect(focusGained)
UserInputService.WindowFocusReleased:Connect(focusReleased)창 포커스 이탈 스크립트 (스크립트)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local awayEvent = Instance.new("RemoteEvent")
awayEvent.Name = "AwayEvent"
awayEvent.Parent = ReplicatedStorage
local function manageForceField(player, away)
if away then
local forceField = Instance.new("ForceField")
forceField.Parent = player.Character
else
local forceField = player.Character:FindFirstChildOfClass("ForceField")
if forceField then
forceField:Destroy()
end
end
end
awayEvent.OnServerEvent:Connect(manageForceField)