User Input Service
요약
속성
MouseIcon:ContentId |
메서드
CreateVirtualInput(target: Instance?):Object |
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 참조
속성
Accelerometer Enabled
코드 샘플
가속도계를 사용하여 공 이동하기
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)
endModal Enabled
Mouse Icon
User Input Service. Mouse Icon: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()Mouse Icon Content
코드 샘플
사용자 정의 마우스 아이콘
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()Preferred Input
코드 샘플
선호 입력 감지
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)User Head C Frame
VR Enabled
메서드
Create Virtual Input
Gamepad Supports
User Input Service: Gamepad Supports(
매개 변수
반환
Get Device Acceleration
코드 샘플
출력 장치 가속도
local UserInputService = game:GetService("UserInputService")
if UserInputService.AccelerometerEnabled then
local acceleration = UserInputService:GetDeviceAcceleration().Position
print(acceleration)
else
warn("장치에 활성화된 가속도가 없기 때문에 장치 가속도를 가져올 수 없습니다!")
endGet Device Gravity
코드 샘플
자이로스코프로 물체 이동하기
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)
endGet Device Rotation
Get Gamepad Connected
매개 변수
반환
Get Gamepad State
매개 변수
반환
Get Image For Key Code
매개 변수
반환
ContentId
코드 샘플
UserInputService - 키코드에 대한 이미지 가져오기
local UserInputService = game:GetService("UserInputService")
local imageLabel = script.Parent
local key = Enum.KeyCode.ButtonA
local mappedIconImage = UserInputService:GetImageForKeyCode(key)
imageLabel.Image = mappedIconImageGet Last Input Type
코드 샘플
마지막 입력 유형 감지
local UserInputService = game:GetService("UserInputService")
if UserInputService:GetLastInputType() == Enum.UserInputType.Keyboard then
print("가장 최근 입력은 키보드였습니다!")
endGet Mouse Buttons Pressed
반환
코드 샘플
눌린 마우스 버튼 확인
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)Get Mouse Delta
반환
코드 샘플
마우스 델타 가져오기
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)Get String For Key Code
매개 변수
| 기본값: Default |
반환
Get Supported Gamepad Key Codes
매개 변수
반환
Get User C Frame
Is Gamepad Button Down
User Input Service: Is Gamepad Button Down(
매개 변수
반환
Is Mouse Button Pressed
매개 변수
반환
매개 변수
반환
Recenter User Head C Frame
User Input Service: Recenter User Head C Frame():()
반환
()
매개 변수
반환
()
이벤트
Device Acceleration Changed
매개 변수
코드 샘플
가속도계를 사용하여 플레이어 제어하기
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)
endDevice Gravity Changed
매개 변수
코드 샘플
가속도계를 사용하여 공 이동하기
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)
endDevice Rotation Changed
매개 변수
Gamepad Connected
매개 변수
Gamepad Disconnected
매개 변수
Input Began
매개 변수
Input Changed
매개 변수
Input Ended
매개 변수
Jump Request
코드 샘플
기본 점프 비활성화
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)Last Input Type Changed
매개 변수
Pointer Action
Text Box Focused
매개 변수
코드 샘플
포커스 및 포커스 해제 시 텍스트 박스 수정
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)Text Box Focus Released
매개 변수
코드 샘플
포커스 및 포커스 해제 시 텍스트 박스 수정
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)Touch Drag
User Input Service. Touch Drag(
매개 변수
Touch Ended
매개 변수
Touch Long Press
User Input Service. Touch Long Press(
매개 변수
Touch Moved
매개 변수
Touch Pan
User Input Service. Touch Pan(
touch Positions:{any}, total Translation:Vector2, velocity:Vector2, state:Enum.UserInputState, game Processed Event:boolean
매개 변수
Touch Pinch
User Input Service. Touch Pinch(
touch Positions:{any}, scale:number, velocity:number, state:Enum.UserInputState, game Processed Event:boolean
매개 변수
Touch Rotate
User Input Service. Touch Rotate(
touch Positions:{any}, rotation:number, velocity:number, state:Enum.UserInputState, game Processed Event:boolean
매개 변수
Touch Started
매개 변수
Touch Swipe
User Input Service. Touch Swipe(
매개 변수
Touch Tap
Touch Tap In World
User C Frame Changed
Window Focus Released
코드 샘플
창 포커스 이탈 스크립트 (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)