UserInputService

사용되지 않는 항목 표시

*이 콘텐츠는 AI(베타)를 사용해 번역되었으며, 오류가 있을 수 있습니다. 이 페이지를 영어로 보려면 여기를 클릭하세요.

만들 수 없음
서비스
복제되지 않음

UserInputService 는 사용자 장치에서 사용할 수 있는 다양한 유형의 입력을 감지하고 캡처하는 데 사용되는 서비스입니다.

이 서비스의 주요 목적은 게임패드, 터치 스크린 및 키보드와 같은 다양한 입력 형식과 협력하여 경험을 가능하게 하는 것입니다.그것은 장치에 따라 다른 작업을 수행할 수 있는 LocalScript 을 허용하고, 궁극적으로 최고의 사용자 환경을 제공합니다.

이 서비스의 일부 사용은 GUI, 도구 및 기타 게임 인스턴스와 상호작용할 때 사용자 입력을 감지하는 것입니다.사용자 입력을 감지하려면 서비스가 서비스 이벤트를 찾아야 합니다.예를 들어, 서비스는 사용자가 UserInputService.TouchStarted 를 사용하여 모바일 장치의 화면을 터치하거나 UserInputService.GamepadConnected 를 사용하여 Xbox 컨트롤러와 같은 게임패드를 장치에 연결할 때와 같은 이벤트를 감지할 수 있습니다.

이 서비스는 클라이언트 측 전용이므로, 클라이언트가 요구하는 또는 에서만 작동합니다.사용자 입력 서비스가 클라이언트 측 전용이기 때문에, 게임의 사용자는 자신의 입력만 감지할 수 있으며 다른 사람의 입력은 감지할 수 없습니다.

또한 참조하십시오 ContextActionService, 여러 사용자 입력에 함수를 바인딩할 수 있는 서비스.

요약

속성

  • 읽기 전용
    복제되지 않음
    병렬 읽기

    사용자의 장치에 가속기가 있는지 여부를 설명합니다.

  • 읽기 전용
    복제되지 않음
    병렬 읽기

    사용자가 사용하는 장치에 사용 가능한 게임패드가 있는지 여부를 설명합니다.

  • 읽기 전용
    복제되지 않음
    병렬 읽기

    사용자의 장치에 자이로스코프가 있는지 여부를 설명합니다.

  • 읽기 전용
    복제되지 않음
    병렬 읽기

    사용자의 장치에 사용 가능한 키보드가 있는지 여부를 설명합니다.

  • 사용자의 마우스를 자유롭게 이동할 수 있는지 또는 잠겨 있는지 여부를 결정합니다.

  • 복제되지 않음
    병렬 읽기

    사용자의 Mouse의 델타(변경) 출력을 확장합니다.

  • 읽기 전용
    복제되지 않음
    병렬 읽기

    사용자의 장치에 마우스가 있는지 여부를 설명합니다.

  • MouseIcon:ContentId
    병렬 읽기

    사용자 마우스 아이콘으로 사용된 이미지의 콘텐츠 ID.

  • Mouse 아이콘이 표시되는지 여부를 결정합니다.

  • 읽기 전용
    복제되지 않음
    병렬 읽기

    화면 키보드의 위치를 결정합니다.

  • 읽기 전용
    복제되지 않음
    병렬 읽기

    화면 키보드의 크기를 결정합니다.

  • 읽기 전용
    복제되지 않음
    병렬 읽기

    화면에 키보드가 현재 표시되는지 여부를 설명합니다. Describes whether an on-screen keyboard is currently visible on the user's screen.

  • 읽기 전용
    복제되지 않음
    병렬 읽기
  • 읽기 전용
    복제되지 않음
    병렬 읽기

    사용자의 현재 장치에 터치 스크린이 있는지 여부를 설명합니다.

  • 읽기 전용
    복제되지 않음
    병렬 읽기

    사용자가 가상 현실 헤드셋을 사용하는지 여부를 나타냅니다.

메서드

이벤트

속성

AccelerometerEnabled

읽기 전용
복제되지 않음
병렬 읽기

이 속성은 사용자의 장치에 가속기가 있는지 여부를 설명합니다

가속도계는 가속(속도 변화)을 측정하는 대부분의 모바일 장치에서 찾을 수 있는 구성 요소입니다.

예를 들어 다음 코드 스니펫은 사용자의 장치에 가속기가 있는지 확인하는 방법을 보여줍니다.


local UserInputService = game:GetService("UserInputService")
local accelerometerEnabled = UserInputService.AccelerometerEnabled
if accelerometerEnabled then
print("Accelerometer enabled!")
else
print("Accelerometer not enabled!")
end

장치에 가속기가 활성화되어 있으면 UserInputService:GetDeviceAcceleration() 함수를 사용하여 장치의 현재 가속을 얻거나 UserInputService.DeviceAccelerationChanged 이벤트를 사용하여 장치의 가속이 변경될 때 추적할 수 있습니다.

클라이언트 측만 있는 As UserInputService는 이 속성을 LocalScript에서만 사용할 수 있습니다.

코드 샘플

This code adds a force on a part so that it falls in the direction of actual gravity relative to the user's device. In order for this example to work as expected, it must be placed in a LocalScript and the user's device must have an accelerometer.

Move a Ball using the Accelerometer

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)
end

GamepadEnabled

읽기 전용
복제되지 않음
병렬 읽기

이 속성은 사용자가 사용하는 장치에 사용 가능한 게임패드가 있는지 여부를 설명합니다.게임패드가 사용 가능하면 UserInputService:GetConnectedGamepads()를 사용하여 연결된 게임패드 목록을 검색할 수 있습니다.

클라이언트 측만 있는 As UserInputService는 이 속성을 LocalScript에서만 사용할 수 있습니다.

참조하세요:

GyroscopeEnabled

읽기 전용
복제되지 않음
병렬 읽기

이 속성은 사용자의 장치에 자이로스코프가 있는지 여부를 설명합니다.

자이로스코프는 방향과 회전 속도를 감지하는 대부분의 모바일 장치에서 찾을 수 있는 구성 요소입니다.

사용자의 장치에 자이로스코프가 있는 경우 UserInputService:GetDeviceRotation() 함수와 UserInputService.DeviceRotationChanged 이벤트를 사용하여 게임에 통합할 수 있습니다.


local UserInputService = game:GetService("UserInputService")
local gyroIsEnabled = UserInputService.GyroscopeEnabled
if gyroIsEnabled then
print("Gyroscope is enabled!")
else
print("Gyroscope is not enabled!")
end

클라이언트 측만 있는 As UserInputService는 이 속성을 LocalScript에서만 사용할 수 있습니다.

KeyboardEnabled

읽기 전용
복제되지 않음
병렬 읽기

이 속성은 사용자의 장치에 사용 가능한 키보드가 있는지 여부를 설명합니다.이 속성은 사용자의 장치에 사용 가능한 키보드가 있을 때 true이고, 없을 때는 false입니다.

사용자에게 사용 가능한 키보드가 있는지 여부를 결정하는 데 사용할 수 있으며, 키보드 입력을 확인하려는 경우 UserInputService:IsKeyDown() 또는 UserInputService:GetKeysPressed()를 사용하여 확인할 수 있는지 확인하려는 경우에 중요할 수 있습니다.

클라이언트 측만 있는 As UserInputService는 이 속성을 LocalScript에서만 사용할 수 있습니다.

코드 샘플

이 예제에서는 키보드 활성화true이고 키보드 활성화false인 경우 "사용자의 장치에 사용 가능한 키보드가 있습니다!"라고 인쇄합니다.

키보드가 활성화되었는지 확인

local UserInputService = game:GetService("UserInputService")
if UserInputService.KeyboardEnabled then
print("The user's device has an available keyboard!")
else
print("The user's device does not have an available keyboard!")
end

MouseBehavior

병렬 읽기

이 속성은 사용자의 마우스가 Enum.MouseBehavior 열거형에 따라 어떻게 동작하는지 설정합니다. 세 가지 값으로 설정할 수 있습니다.

이 속성의 값은 이벤트 추적 마우스 이동 감도에 영향을 주지 않습니다.예를 들어, GetMouseDelta 는 마우스가 잠겨 있든 아니든 상관없이 사용자의 화면에서 동일한 Vector2 화면 위치를 픽셀로 반환합니다.결과적으로 카메라를 제어하는 기본 스크립트와 같은 속성의 영향을 받지 않습니다.

이 속성은 플레이어의 오른쪽 마우스 버튼이 아래로 가지 않은 경우 와 가 활성화된 경우에 재정의됩니다. 그렇지 않으면 이 속성은 무시됩니다.

마우스가 잠겨 있으면, UserInputService.InputChanged 는 플레이어가 마우스를 이동할 때 여전히 발사되고 마우스가 이동하려고 시도한 델타를 전달합니다.또한, 플레이어가 게임에서 강퇴되면 마우스가 강제로 잠금 해제됩니다.

클라이언트 측만 있는 As UserInputService는 이 속성을 LocalScript에서만 사용할 수 있습니다.

코드 샘플

이 예제에서는 플레이어의 FieldOfView()MouseDeltaSensitivity()를 줄이는 망원경 스크립트를 생성하여 플레이어가 MouseEnabled() 마우스 클릭을 남겼을 때 발생합니다.스크립트는 또한 플레이어의 마우스 클릭의 세계 위치로 향하도록 지적합니다.

플레이어가 마우스 클릭을 다시 할 때 플레이어의 카메라는 플레이어가 스크립트로 확대했을 때와 동일한 시야와 필드로 되돌아갑니다.

플레이어가 망원경을 사용하는 동안 스크립트는 플레이어의 마우스를 화면 중앙에 고정하여 플레이어의 MouseBehavior()를 잠금 센터로 설정하여 잠금합니다.플레이어의 카메라는 플레이어가 마우스를 이동할 때 화면 위치 변경을 나타내는 속성을 통해 이동합니다.The player's camera moves when the player moves their mouse according to the property passed by indicating the mouse's change in screen position.

이 예제가 예상대로 작동하려면 LocalScript 에 배치되어야 합니다.

망원경 스크립트 만들기

local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.CharacterAdded:Wait()
local head = character:WaitForChild("Head", false)
local mouse = player:GetMouse()
local zoomed = false
local camera = game.Workspace.CurrentCamera
local target = nil
local originalProperties = {
FieldOfView = nil,
_CFrame = nil,
MouseBehavior = nil,
MouseDeltaSensitivity = nil,
}
local AngleX, TargetAngleX = 0, 0
local AngleY, TargetAngleY = 0, 0
-- 확대하기 전에 카메라를 CFrame과 FieldOfView로 재설정
local function ResetCamera()
target = nil
camera.CameraType = Enum.CameraType.Custom
camera.CFrame = originalProperties._CFrame
camera.FieldOfView = originalProperties.FieldOfView
UserInputService.MouseBehavior = originalProperties.MouseBehavior
UserInputService.MouseDeltaSensitivity = originalProperties.MouseDeltaSensitivity
end
local function ZoomCamera()
-- 스크립트에 의해 카메라가 변경되도록 허용
camera.CameraType = Enum.CameraType.Scriptable
-- 확대하기 전에 카메라 속성 저장
originalProperties._CFrame = camera.CFrame
originalProperties.FieldOfView = camera.FieldOfView
originalProperties.MouseBehavior = UserInputService.MouseBehavior
originalProperties.MouseDeltaSensitivity = UserInputService.MouseDeltaSensitivity
-- 카메라 확대
target = mouse.Hit.Position
local eyesight = head.Position
camera.CFrame = CFrame.new(eyesight, target)
camera.Focus = CFrame.new(target)
camera.FieldOfView = 10
-- 마우스 잠금 및 속도 늦추기
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
UserInputService.MouseDeltaSensitivity = 1
-- 배율 각도 재설정
AngleX, TargetAngleX = 0, 0
AngleY, TargetAngleY = 0, 0
end
-- 카메라 줌/축소 전환
local function MouseClick()
if zoomed then
-- 카메라 축소 해제
ResetCamera()
else
-- 카메라 확대
ZoomCamera()
end
zoomed = not zoomed
end
local function MouseMoved(input)
if zoomed then
local sensitivity = 0.6 -- 높이가 더 높아지면 위아래로 찾기가 더 어려워집니다; 0~1 사이의 모든 것을 추천합니다
local smoothness = 0.05 -- 0~1 사이의 모든 것을 추천합니다
local delta = Vector2.new(input.Delta.x / sensitivity, input.Delta.y / sensitivity) * smoothness
local X = TargetAngleX - delta.y
local Y = TargetAngleY - delta.x
TargetAngleX = (X >= 80 and 80) or (X <= -80 and -80) or X
TargetAngleY = (Y >= 80 and 80) or (Y <= -80 and -80) or Y
AngleX = AngleX + (TargetAngleX - AngleX) * 0.35
AngleY = AngleY + (TargetAngleY - AngleY) * 0.15
camera.CFrame = CFrame.new(head.Position, target)
* CFrame.Angles(0, math.rad(AngleY), 0)
* CFrame.Angles(math.rad(AngleX), 0, 0)
end
end
local function InputBegan(input, _gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
MouseClick()
end
end
local function InputChanged(input, _gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.MouseMovement then
MouseMoved(input)
end
end
if UserInputService.MouseEnabled then
UserInputService.InputBegan:Connect(InputBegan)
UserInputService.InputChanged:Connect(InputChanged)
end

MouseDeltaSensitivity

복제되지 않음
병렬 읽기

이 속성은 사용자의 Mouse 감도를 결정합니다.

민감도는 물리적 마우스의 이동이 게임 내 마우스 이동으로 변환되는 범위를 결정합니다.이를 사용하여 민감한 이벤트 추적 마우스 이동, 예를 들어 GetMouseDelta ,이 마우스 이동에 대해 조정될 수 있습니다.

이 속성은 마우스 아이콘의 이동에 영향을 주지 않습니다.클라이언트의 설정 메뉴의 설정 탭에 있는 카메라 감도 설정에도 영향을 주지 않으며, 이는 이벤트 추적 마우스 이동의 감도도 조정합니다.

이 속성의 최대 값은 10이고 최소 값은 0입니다.낮은 값은 낮은 민감도에 해당하고 높은 값은 높은 민감도에 해당합니다.

민감도가 0인 경우 마우스의 이동을 추적하는 이벤트는 여전히 발생하지만 마우스 위치 변경을 나타내는 모든 매개변수와 속성은 Vector2.new() 또는 Vector3.new() 경우 마우스의 InputObject.Delta 에서 반환됩니다.예를 들어, GetMouseDelta 는 항상 (0, 0)을 반환합니다.

코드 샘플

이 예제에서는 플레이어의 FieldOfView()MouseDeltaSensitivity()를 줄이는 망원경 스크립트를 생성하여 플레이어가 MouseEnabled() 마우스 클릭을 남겼을 때 발생합니다.스크립트는 또한 플레이어의 마우스 클릭의 세계 위치로 향하도록 지적합니다.

플레이어가 마우스 클릭을 다시 할 때 플레이어의 카메라는 플레이어가 스크립트로 확대했을 때와 동일한 시야와 필드로 되돌아갑니다.

플레이어가 망원경을 사용하는 동안 스크립트는 플레이어의 마우스를 화면 중앙에 고정하여 플레이어의 MouseBehavior()를 잠금 센터로 설정하여 잠금합니다.플레이어의 카메라는 플레이어가 마우스를 이동할 때 화면 위치 변경을 나타내는 속성을 통해 이동합니다.The player's camera moves when the player moves their mouse according to the property passed by indicating the mouse's change in screen position.

이 예제가 예상대로 작동하려면 LocalScript 에 배치되어야 합니다.

망원경 스크립트 만들기

local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.CharacterAdded:Wait()
local head = character:WaitForChild("Head", false)
local mouse = player:GetMouse()
local zoomed = false
local camera = game.Workspace.CurrentCamera
local target = nil
local originalProperties = {
FieldOfView = nil,
_CFrame = nil,
MouseBehavior = nil,
MouseDeltaSensitivity = nil,
}
local AngleX, TargetAngleX = 0, 0
local AngleY, TargetAngleY = 0, 0
-- 확대하기 전에 카메라를 CFrame과 FieldOfView로 재설정
local function ResetCamera()
target = nil
camera.CameraType = Enum.CameraType.Custom
camera.CFrame = originalProperties._CFrame
camera.FieldOfView = originalProperties.FieldOfView
UserInputService.MouseBehavior = originalProperties.MouseBehavior
UserInputService.MouseDeltaSensitivity = originalProperties.MouseDeltaSensitivity
end
local function ZoomCamera()
-- 스크립트에 의해 카메라가 변경되도록 허용
camera.CameraType = Enum.CameraType.Scriptable
-- 확대하기 전에 카메라 속성 저장
originalProperties._CFrame = camera.CFrame
originalProperties.FieldOfView = camera.FieldOfView
originalProperties.MouseBehavior = UserInputService.MouseBehavior
originalProperties.MouseDeltaSensitivity = UserInputService.MouseDeltaSensitivity
-- 카메라 확대
target = mouse.Hit.Position
local eyesight = head.Position
camera.CFrame = CFrame.new(eyesight, target)
camera.Focus = CFrame.new(target)
camera.FieldOfView = 10
-- 마우스 잠금 및 속도 늦추기
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
UserInputService.MouseDeltaSensitivity = 1
-- 배율 각도 재설정
AngleX, TargetAngleX = 0, 0
AngleY, TargetAngleY = 0, 0
end
-- 카메라 줌/축소 전환
local function MouseClick()
if zoomed then
-- 카메라 축소 해제
ResetCamera()
else
-- 카메라 확대
ZoomCamera()
end
zoomed = not zoomed
end
local function MouseMoved(input)
if zoomed then
local sensitivity = 0.6 -- 높이가 더 높아지면 위아래로 찾기가 더 어려워집니다; 0~1 사이의 모든 것을 추천합니다
local smoothness = 0.05 -- 0~1 사이의 모든 것을 추천합니다
local delta = Vector2.new(input.Delta.x / sensitivity, input.Delta.y / sensitivity) * smoothness
local X = TargetAngleX - delta.y
local Y = TargetAngleY - delta.x
TargetAngleX = (X >= 80 and 80) or (X <= -80 and -80) or X
TargetAngleY = (Y >= 80 and 80) or (Y <= -80 and -80) or Y
AngleX = AngleX + (TargetAngleX - AngleX) * 0.35
AngleY = AngleY + (TargetAngleY - AngleY) * 0.15
camera.CFrame = CFrame.new(head.Position, target)
* CFrame.Angles(0, math.rad(AngleY), 0)
* CFrame.Angles(math.rad(AngleX), 0, 0)
end
end
local function InputBegan(input, _gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
MouseClick()
end
end
local function InputChanged(input, _gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.MouseMovement then
MouseMoved(input)
end
end
if UserInputService.MouseEnabled then
UserInputService.InputBegan:Connect(InputBegan)
UserInputService.InputChanged:Connect(InputChanged)
end

MouseEnabled

읽기 전용
복제되지 않음
병렬 읽기

이 속성은 사용자의 장치에 마우스가 있는지 여부를 설명합니다.이 속성은 사용자의 장치에 사용 가능한 마우스가 있을 때 true이고, 없을 때는 false입니다.


local UserInputService = game:GetService("UserInputService")
if UserInputService.MouseEnabled then
print("The user's device has an available mouse!")
else
print("The user's device does not have an available mouse!")
end

마우스 기능을 사용하기 전에 이것을 확인하는 것이 중요합니다.

클라이언트 측만 있는 As UserInputService는 이 속성을 LocalScript에서만 사용할 수 있습니다.

참조하세요:

코드 샘플

이 예제에서는 플레이어의 FieldOfView()MouseDeltaSensitivity()를 줄이는 망원경 스크립트를 생성하여 플레이어가 MouseEnabled() 마우스 클릭을 남겼을 때 발생합니다.스크립트는 또한 플레이어의 마우스 클릭의 세계 위치로 향하도록 지적합니다.

플레이어가 마우스 클릭을 다시 할 때 플레이어의 카메라는 플레이어가 스크립트로 확대했을 때와 동일한 시야와 필드로 되돌아갑니다.

플레이어가 망원경을 사용하는 동안 스크립트는 플레이어의 마우스를 화면 중앙에 고정하여 플레이어의 MouseBehavior()를 잠금 센터로 설정하여 잠금합니다.플레이어의 카메라는 플레이어가 마우스를 이동할 때 화면 위치 변경을 나타내는 속성을 통해 이동합니다.The player's camera moves when the player moves their mouse according to the property passed by indicating the mouse's change in screen position.

이 예제가 예상대로 작동하려면 LocalScript 에 배치되어야 합니다.

망원경 스크립트 만들기

local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.CharacterAdded:Wait()
local head = character:WaitForChild("Head", false)
local mouse = player:GetMouse()
local zoomed = false
local camera = game.Workspace.CurrentCamera
local target = nil
local originalProperties = {
FieldOfView = nil,
_CFrame = nil,
MouseBehavior = nil,
MouseDeltaSensitivity = nil,
}
local AngleX, TargetAngleX = 0, 0
local AngleY, TargetAngleY = 0, 0
-- 확대하기 전에 카메라를 CFrame과 FieldOfView로 재설정
local function ResetCamera()
target = nil
camera.CameraType = Enum.CameraType.Custom
camera.CFrame = originalProperties._CFrame
camera.FieldOfView = originalProperties.FieldOfView
UserInputService.MouseBehavior = originalProperties.MouseBehavior
UserInputService.MouseDeltaSensitivity = originalProperties.MouseDeltaSensitivity
end
local function ZoomCamera()
-- 스크립트에 의해 카메라가 변경되도록 허용
camera.CameraType = Enum.CameraType.Scriptable
-- 확대하기 전에 카메라 속성 저장
originalProperties._CFrame = camera.CFrame
originalProperties.FieldOfView = camera.FieldOfView
originalProperties.MouseBehavior = UserInputService.MouseBehavior
originalProperties.MouseDeltaSensitivity = UserInputService.MouseDeltaSensitivity
-- 카메라 확대
target = mouse.Hit.Position
local eyesight = head.Position
camera.CFrame = CFrame.new(eyesight, target)
camera.Focus = CFrame.new(target)
camera.FieldOfView = 10
-- 마우스 잠금 및 속도 늦추기
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
UserInputService.MouseDeltaSensitivity = 1
-- 배율 각도 재설정
AngleX, TargetAngleX = 0, 0
AngleY, TargetAngleY = 0, 0
end
-- 카메라 줌/축소 전환
local function MouseClick()
if zoomed then
-- 카메라 축소 해제
ResetCamera()
else
-- 카메라 확대
ZoomCamera()
end
zoomed = not zoomed
end
local function MouseMoved(input)
if zoomed then
local sensitivity = 0.6 -- 높이가 더 높아지면 위아래로 찾기가 더 어려워집니다; 0~1 사이의 모든 것을 추천합니다
local smoothness = 0.05 -- 0~1 사이의 모든 것을 추천합니다
local delta = Vector2.new(input.Delta.x / sensitivity, input.Delta.y / sensitivity) * smoothness
local X = TargetAngleX - delta.y
local Y = TargetAngleY - delta.x
TargetAngleX = (X >= 80 and 80) or (X <= -80 and -80) or X
TargetAngleY = (Y >= 80 and 80) or (Y <= -80 and -80) or Y
AngleX = AngleX + (TargetAngleX - AngleX) * 0.35
AngleY = AngleY + (TargetAngleY - AngleY) * 0.15
camera.CFrame = CFrame.new(head.Position, target)
* CFrame.Angles(0, math.rad(AngleY), 0)
* CFrame.Angles(math.rad(AngleX), 0, 0)
end
end
local function InputBegan(input, _gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
MouseClick()
end
end
local function InputChanged(input, _gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.MouseMovement then
MouseMoved(input)
end
end
if UserInputService.MouseEnabled then
UserInputService.InputBegan:Connect(InputBegan)
UserInputService.InputChanged:Connect(InputChanged)
end

MouseIcon

ContentId
병렬 읽기

MouseIcon 속성은 포인터로 사용되는 이미지를 결정합니다.비어 있으면 기본 화살표가 사용됩니다.커서가 특정 UI 개체(ImageButton, TextButton, TextBox, 또는 ProximityPrompt와 같은)에 머물러 있는 동안, 이 이미지가 재정의되어 일시적으로 무시됩니다.

커서를 완전히 숨기려면 투명한 이미지를 사용하지 마십시오 . 대신 false로 UserInputService.MouseIconEnabled하십시오.

코드 샘플

이 예제에서는 사용자 마우스 아이콘을 드래곤 이미지처럼 변경합니다.

사용자 입력 서비스.MouseIcon

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()
print(UserInputService.MouseIcon)

MouseIconEnabled

병렬 읽기

이 속성은 마우스의 아이콘이 표시될 때 아이콘이 표시되는지 여부를 결정합니다. 마우스의 아이콘이 표시되지 않을 때 아니요.

예를 들어 아래의 코드 스니펫은 마우스의 아이콘을 숨깁니다.


local UserInputService = game:GetService("UserInputService")
UserInputService.MouseIconEnabled = false

클라이언트 측만 있는 As UserInputService는 이 속성을 LocalScript에서만 사용할 수 있습니다.

코드 샘플

This example hides the mouse icon while the player beings using their keyboard, such as to chat or enter text into a TextBox. The mouse icon reappears when the user resumes mouse input.

This uses the LastInputType() event to determine when the user begins keyboard input and mouse input - based on the value of the lastInputType argument.

In order for this example to work as expected, it should be placed in a LocalScript.

Hide Mouse During Keyboard Input

local UserInputService = game:GetService("UserInputService")
local mouseInput = {
Enum.UserInputType.MouseButton1,
Enum.UserInputType.MouseButton2,
Enum.UserInputType.MouseButton3,
Enum.UserInputType.MouseMovement,
Enum.UserInputType.MouseWheel,
}
local keyboard = Enum.UserInputType.Keyboard
local function toggleMouse(lastInputType)
if lastInputType == keyboard then
UserInputService.MouseIconEnabled = false
return
end
for _, mouse in pairs(mouseInput) do
if lastInputType == mouse then
UserInputService.MouseIconEnabled = true
return
end
end
end
UserInputService.LastInputTypeChanged:Connect(toggleMouse)

OnScreenKeyboardPosition

읽기 전용
복제되지 않음
병렬 읽기

이 속성은 화면에 표시되는 키보드의 위치를 픽셀로 설명합니다. 키보드의 위치는 표시되지 않을 때 Vector2.new(0, 0)입니다.

As UserInputService 는 클라이언트 측 전용이므로, 이 속성은 LocalScript 또는 Script 에서만 사용할 수 있으며 RunContextEnum.RunContext.Client 로 설정됩니다.

또한 참조하십시오 OnScreenKeyboardVisibleOnScreenKeyboardSize .

OnScreenKeyboardSize

읽기 전용
복제되지 않음
병렬 읽기

이 속성은 픽셀로 화면 키보드의 크기를 설명합니다. 키보드의 크기는 표시되지 않을 때 Vector2.new(0, 0)입니다.

As UserInputService 는 클라이언트 측 전용이므로, 이 속성은 LocalScript 또는 Script 에서만 사용할 수 있으며 RunContextEnum.RunContext.Client 로 설정됩니다.

또한 참조하십시오 OnScreenKeyboardVisibleOnScreenKeyboardPosition .

OnScreenKeyboardVisible

읽기 전용
복제되지 않음
병렬 읽기

이 속성은 사용자 화면에 현재 표시되는 화면 키보드인지 여부를 설명합니다.

As UserInputService 는 클라이언트 측 전용이므로, 이 속성은 LocalScript 또는 Script 에서만 사용할 수 있으며 RunContextEnum.RunContext.Client 로 설정됩니다.

또한 참조하십시오 OnScreenKeyboardSizeOnScreenKeyboardPosition .

PreferredInput

읽기 전용
복제되지 않음
병렬 읽기

TouchEnabled

읽기 전용
복제되지 않음
병렬 읽기

이 속성은 사용자의 현재 장치에 터치 스크린이 있는지 여부를 설명합니다.

속성은 사용자의 장치에 터치 스크린이 있는지 여부와 터치 이벤트가 발생할지 여부를 결정하는 데 사용됩니다.터치 활성화가 true이면 UserInputService.TouchStartedUserInputService.TouchEnded와 같은 사용자 입력 서비스 이벤트를 사용하여 사용자가 장치의 화면을 터치하기 시작하고 중지하는 시기를 추적할 수 있습니다.

아래 코드 스니펫은 사용자의 장치에 터치 스크린이 있는지 여부를 인쇄합니다.


local UserInputService = game:GetService("UserInputService")
if UserInputService.TouchEnabled then
print("The user's device has a touchscreen!")
else
print("The user's device does not have a touchscreen!")
end

참조하세요:

VREnabled

읽기 전용
복제되지 않음
병렬 읽기

이 속성은 사용자가 VR(가상 현실) 장치를 사용하는지 여부를 설명합니다.

VR 장치가 활성화되면 UserInputService:GetUserCFrame()와 같은 함수를 통해 위치와 이동을 상호 작용할 수 있습니다.또한 UserInputService.UserCFrameChanged 이벤트를 사용하여 VR 장치 이동에 반응할 수 있습니다.


local UserInputService = game:GetService("UserInputService")
local isUsingVR = UserInputService.VREnabled
if isUsingVR then
print("User is using a VR headset!")
else
print("User is not using a VR headset!")
end

클라이언트 측만 있는 As UserInputService는 이 속성을 LocalScript에서만 사용할 수 있습니다.

참조하세요:

코드 샘플

This example demonstrates how to implement a head tracking script that mirrors the movement of a virtual reality (VR) headset (the user's actual head) to their in-game character's head.

The example first check if the user is using a VR device by checking the value of the VREnabled() property. This example only works if the user is using a VR headset.

To determine the initial CFrame of the character's head, the code sample calls GetUserCFrame() and passes Enum.UserCFrame.Head as the argument.

To update the head's CFrame whenever the user's VR headset moves, the example connects the VRService.UserCFrameChanged event to the TrackHead() function. When the event fires to indicate that a VR device moved, TrackHead() checks if the headset moved. If the headset moved, the function updates the CFrame of the character's head to the CFrame value provided as an argument.

As the UserCFrame enum also tracks VR left and right hand devices, the concept of VR device tracking can be expanded to other character bodyparts.

In order for the example to work as expected, it must be placed in a LocalScript.

VR Head Tracking

local VRService = game:GetService("VRService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.CharacterAdded:Wait()
local head = character:WaitForChild("Head")
local function TrackHead(inputType, value)
if inputType == Enum.UserCFrame.Head then
head.CFrame = value
end
end
if VRService.VREnabled then
-- Set the initial CFrame
head.CFrame = VRService:GetUserCFrame(Enum.UserCFrame.Head)
-- Track VR headset movement and mirror for character's head
VRService.UserCFrameChanged:Connect(TrackHead)
end

메서드

GamepadSupports

이 함수는 지정된 Enum.UserInputType 게임패드가 지정된 Enum.KeyCode에 해당하는 버튼을 지원하는지 여부를 반환합니다.이 함수는 유효한 게임패드 입력을 결정하는 데 사용됩니다.

어떤 Enum.UserInputType가 연결되었는지 확인하려면 UserInputService:GetConnectedGamepads()를 사용하십시오.

클라이언트 측만 있는 As UserInputService는 이 함수를 LocalScript에서만 사용할 수 있습니다.

참조하세요:

매개 변수

gamepadNum: Enum.UserInputType

게임패드의 Enum.UserInputType .

기본값: ""
gamepadKeyCode: Enum.KeyCode

질문의 버튼의 Enum.KeyCode .

기본값: ""

반환

지정된 게임패드가 지정된 Enum.KeyCode에 해당하는 버튼을 지원하는지 여부.

GetConnectedGamepads

이 함수는 현재 연결된 게임패드 배열을 반환합니다 Enum.UserInputType 게임패드.게임패드가 연결되지 않으면 이 배열은 비어 있습니다.또한 게임패드인 UserInputType 개체만 반환합니다.예를 들어, 이 이벤트는 연결된 Gamepad1 개체를 반환하지만 키보드 개체는 아닙니다.

예를 들어 다음 코드 스니펫은 연결된 게임패드를 검색하고 연결된 게임패드라는 변수에 저장합니다.


local UserInputService = game:GetService("UserInputService")
local connectedGamepads = UserInputService:GetConnectedGamepads()

특정 게임패드가 연결되었는지 확인하려면 UserInputService:GetGamepadConnected()를 사용하십시오.

클라이언트 측만 있는 As UserInputService는 이 함수를 LocalScript에서만 사용할 수 있습니다.

참조하세요:


반환

사용자 장치에 연결된 게임패드와 일치하는 배열 UserInputTypes의 배열.

GetDeviceAcceleration

GetDeviceAcceleration 함수는 사용자의 장치의 현재 가속을 결정합니다.장치의 현재 가속을 설명하는 InputObject를 반환합니다.

이것이 작동하려면 사용자의 장치에 가속도계가 활성화되어 있어야 합니다.사용자의 장치에 가속도계가 활성화되어 있는지 확인하려면 UserInputService.AccelerometerEnabled 속성을 확인할 수 있습니다.

사용자의 장치 가속이 변경될 때를 추적하려는 경우 UserInputService.DeviceAccelerationChanged 이벤트를 사용할 수 있습니다.

로컬에서만 발사되므로 LocalScript 에서만 사용할 수 있습니다.


반환

코드 샘플

This example checks if a user's device has an enabled accelerometer and, if true, it outputs the current acceleration.

Output Device Acceleration

local UserInputService = game:GetService("UserInputService")
if UserInputService.AccelerometerEnabled then
local acceleration = UserInputService:GetDeviceAcceleration().Position
print(acceleration)
else
warn("Cannot get device acceleration because device does not have an enabled accelerometer!")
end

GetDeviceGravity

이 함수는 장치의 현재 중력 벡터를 설명하는 InputObject를 반환합니다.

중력 벡터는 장치의 실제 세계 중력 대비 방향으로 결정됩니다.예를 들어, 장치가 완벽하게 세로로 향하면(초상) 중력 벡터는 Vector3.new(0, 0, -9.18)입니다.장치의 왼쪽이 아래를 가리키고 있으면 벡터는 Vector3.new(9.81, 0, 0)입니다.마지막으로, 장치의 뒷면이 아래를 가리키는 경우 벡터는 Vector3.new(0, -9.81, 0)입니다.

이 함수는 사용자의 장치가 게임 내에서 중력에 영향을 주거나 공 같은 게임 내 개체를 이동하도록 활성화하는 데 사용될 수 있습니다.

중력은 모바일 장치와 같이 활성화된 자이로스코프가 있는 장치를 사용하는 플레이어에 대해서만 추적됩니다.

사용자의 장치에 자이로스코프가 활성화되어 있는지 확인하려면 UserInputService.GyroscopeEnabled의 값을 확인하십시오.장치에 자이로스코프가 활성화되어 있으면 사용자 장치의 중력 변화를 추적하기 위해 UserInputService.DeviceGravityChanged 이벤트도 사용할 수 있습니다.

클라이언트 측만 있는 As UserInputService는 이 함수를 LocalScript에서만 사용할 수 있습니다.


반환

코드 샘플

This example implements a level where the bubble will move along the X and Z axes depending on the device's current gryoscope position.

Moving Objects with the Gyroscope

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
-- Bind event to when gyroscope detects change
UserInputService.DeviceGravityChanged:Connect(function(accel)
-- Move the bubble in the world based on the gyroscope data
bubble.Position = Vector3.new(-8 * accel.Position.X, 1.8, -8 * accel.Position.Z)
end)
end

GetDeviceRotation

이 함수는 장치의 현재 회전 벡터를 설명하는 InputObjectCFrame를 반환합니다.

입력 개체로 발사됩니다.입력 개체의 위치 속성은 각 로컬 장치 축의 전체 회전을 추적하는 Enum.InputType.Gyroscope입니다.

장치 회전은 gyroscope를 가진 장치에서만 추적할 수 있습니다.

이 함수가 로컬로 발생하기 때문에, 이 함수는 LocalScript에서만 사용할 수 있습니다.


반환

속성 2개가 포함된 튜플:

  1. 델타 속성은 마지막으로 발생한 회전량을 설명합니다
  2. CF레임은 기기의 현재 회전이 기본 참조 프레임에 대한 회전입니다.

코드 샘플

This example checks if a user's device has an enabled gyroscope and, if true, it outputs the device's current CFrame.

Output Device Rotation

local UserInputService = game:GetService("UserInputService")
if UserInputService.GyroscopeEnabled then
local _, cf = UserInputService:GetDeviceRotation()
print(cf)
else
warn("Cannot get device rotation because device does not have an enabled gyroscope!")
end

GetFocusedTextBox

이 함수는 클라이언트가 현재 집중하고 있는 TextBox를 반환합니다.A TextBox 는 사용자가 수동으로 선택하거나 TextBox:CaptureFocus() 함수를 사용하여 선택을 강제할 수 있습니다.TextBox 가 선택되지 않으면 이 함수는 nil 를 반환합니다.

클라이언트 측만 있는 As UserInputService는 이 함수를 LocalScript에서만 사용할 수 있습니다.

또한 참조하세요

반환

GetGamepadConnected

이 함수는 지정된 Enum.UserInputType 게임패드가 클라이언트에 연결되었는지 여부를 반환합니다.

이를 사용하여 특정 게임패드인 *'게임패드1'*가 클라이언트 장치에 연결되었는지 확인할 수 있습니다.

연결된 모든 게임패드 목록을 검색하려면 UserInputService:GetConnectedGamepads()를 사용하십시오.

클라이언트 측만 있는 As UserInputService는 이 함수를 LocalScript에서만 사용할 수 있습니다.

참조하세요:

매개 변수

gamepadNum: Enum.UserInputType

질문의 게임패드의 Enum.UserInputType .

기본값: ""

반환

게임패드가 Enum.UserInputType와 연결되었는지 여부.

GetGamepadState

이 함수는 지정된 Enum.UserInputType에서 사용 가능한 모든 입력에 대해 InputObjects을 반환하여 각 입력의 마지막 입력 상태를 나타냅니다.

연결된 게임패드의 UserInputTypes를 찾으려면 UserInputService:GetConnectedGamepads()를 사용하십시오.

이 함수는 로컬에서만 발동되므로, LocalScript 에서만 사용할 수 있습니다.

참조하세요:

매개 변수

gamepadNum: Enum.UserInputType

질문의 게임패드와 일치하는 Enum.UserInputType

기본값: ""

반환

지정된 게임패드에 대한 모든 입력의 현재 상태를 나타내는 InputObjects 배열.

GetImageForKeyCode

ContentId

이 메서드는 요청된 Enum.KeyCode를 가져와 현재 연결된 게임패드 장치(Xbox, PlayStation 및 Windows 제한)에 대한 관련 이미지를 반환합니다.즉, 연결된 컨트롤러가 Xbox 원 컨트롤러인 경우 사용자는 Xbox 자산을 볼 수 있습니다.마찬가지로, 연결된 장치가 PlayStation 컨트롤러인 경우 사용자는 PlayStation 자산을 볼 수 있습니다.사용자 지정 자산을 사용하려면 GetStringForKeyCode()를 참조하십시오.

매개 변수

keyCode: Enum.KeyCode

연결된 이미지를 가져올 Enum.KeyCode 대상.

기본값: ""

반환

ContentId

반환된 이미지 자산 ID.

코드 샘플

이 API는 지정된 Enum.KeyCode에 대한 요청된 이미지를 반환합니다.

사용자 입력 서비스 - 키코드에 대한 이미지 가져오기

local UserInputService = game:GetService("UserInputService")
local imageLabel = script.Parent
local key = Enum.KeyCode.ButtonA
local mappedIconImage = UserInputService:GetImageForKeyCode(key)
imageLabel.Image = mappedIconImage

GetKeysPressed

이 함수는 현재 누르고 있는 키와 관련된 InputObjects 배열을 반환합니다.

이 배열은 현재 누르고 있는 키를 결정하기 위해 InputObject.KeyCode 값을 사용하여 반복될 수 있습니다.

특정 키가 누르는지 확인하려면 UserInputService:IsKeyDown()를 사용하십시오.

클라이언트 측만 있는 As UserInputService는 이 함수를 LocalScript에서만 사용할 수 있습니다.


반환

현재 누르고 있는 키와 연결된 배열 InputObjects 의 키.

GetLastInputType

이 함수는 사용자의 최신 입력과 관련된 'Enum.UserInputType'을 반환합니다.

예를 들어, 사용자의 이전 입력이 스페이스바를 누르고 있었다면, 반환된 Enum.UserInputType'키보드' 가 될 것입니다.

이벤트를 사용하여 사용자가 마지막으로 사용한 변경 내용의 시기를 추적할 수 있습니다.

클라이언트 측만 있는 As UserInputService는 이 함수를 LocalScript에서만 사용할 수 있습니다.


반환

사용자의 가장 최근 입력과 연결된 Enum.UserInputType 입니다.

코드 샘플

This example gets the last Enum.UserInputType and outputs if it was keyboard input.

Detect Last Input Type

local UserInputService = game:GetService("UserInputService")
if UserInputService:GetLastInputType() == Enum.UserInputType.Keyboard then
print("Most recent input was keyboard!")
end

GetMouseButtonsPressed

이 함수는 현재 누르고 있는 마우스 버튼에 해당하는 InputObjects 배열을 반환합니다.

이 함수에 의해 추적되는 마우스 버튼에는 다음이 포함됩니다:


<td>설명</td>
</tr>
</thead>
<tr>
<td>마우스 버튼1</td>
<td>왼쪽 마우스 버튼.</td>
</tr>
<tr>
<td>마우스 버튼2</td>
<td>오른쪽 마우스 버튼.</td>
</tr>
<tr>
<td>마우스 버튼3</td>
<td>중간 마우스 버튼.</td>
</tr>
이름

사용자가 함수가 호출될 때 아무 마우스 버튼을 누르지 않으면 빈 배열이 반환됩니다.

클라이언트 측만 있는 As UserInputService는 이 함수를 LocalScript에서만 사용할 수 있습니다.


반환

현재 마우스 버튼이 누르고 있는 것에 해당하는 InputObjects 배열의 배열.

코드 샘플

This example checks if the user pressed MouseButton1 (left), MouseButton2 (right), or both mouse buttons. This can be extended to behave differently depending on which mouse buttons are pressed, including MouseButton3 (middle).

Check Pressed Mouse Buttons

local UserInputService = game:GetService("UserInputService")
UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
-- Return an array of the pressed mouse buttons
local buttonsPressed = UserInputService:GetMouseButtonsPressed()
local m1, m2 = false, false
for _, button in buttonsPressed do
if button.UserInputType == Enum.UserInputType.MouseButton1 then
print("MouseButton1 pressed!")
m1 = true
end
if button.UserInputType == Enum.UserInputType.MouseButton2 then
print("MouseButton2 pressed!")
m2 = true
end
if m1 and m2 then
print("Both mouse buttons pressed!")
end
end
end)

GetMouseDelta

이 함수는 마지막으로 렌더링된 프레임에서 플레이어의 Mouse 위치의 변경, 픽셀로, 변경 내용을 Vector2로 반환합니다.이 함수는 마우스가 UserInputService.MouseBehavior을 사용하여 잠겨 있는 경우에만 작동합니다.마우스가 잠겨 있지 않으면 반환된 Vector2 값이 0이 됩니다.

클라이언트 설정에서 결정된 마우스의 민감도와 UserInputService.MouseDeltaSensitivity , 결과에 영향을 미칠 것입니다.

클라이언트 측만 있는 As UserInputService는 이 함수를 LocalScript에서만 사용할 수 있습니다.


반환

마우스 이동 변경.

코드 샘플

The following example measures any mouse movement in pixels from the last render step to the current render step. If the user has set their camera sensitivity to be higher or lower than 1 in the experience's menu, it will affect the returned value.

Getting 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("The mouse has moved", delta, "since the last step")
end
end
RunService:BindToRenderStep("MeasureMouseMovement", Enum.RenderPriority.Input.Value, onRenderStep)

GetMouseLocation

이 함수는 상단 왼쪽 모서리와 관련하여 플레이어의 Mouse 현재 화면 위치를 나타내는 Vector2 을 반환합니다.이것은 상위 왼쪽과 하위 오른쪽 삽입을 얻기 위해 Enum.ScreenInsets ;를 호출하지 않습니다. 상위 왼쪽과 하위 오른쪽 삽입을 얻으려면 GuiService:GetGuiInset()를 호출하십시오.

마우스 포인터의 위치가 화면 밖이거나 플레이어의 장치에 마우스가 없으면 반환된 값이 결정되지 않습니다.

클라이언트 측만 있는 As UserInputService는 이 함수를 LocalScript에서만 사용할 수 있습니다.


반환

A Vector2 마우스의 현재 화면 위치를 픽셀로 나타내는 것

GetNavigationGamepads

이 함수는 연결되고 GUI 탐색을 위해 활성화된 게임패드 배열 UserInputTypes를 반환합니다.이 목록은 우선 순위가 하락하는 순서로 정렬되어 있으므로 어떤 게임패드에 탐색 컨트롤이 있어야 하는지 확인할 수 있습니다.

연결된 게임패드가 네비게이션 게임패드인지 여부는 네비게이션 GUI를 제어하는 게임패드(들)만 결정합니다.이는 탐색 컨트롤에 영향을 주지 않습니다.

Since UserInputService 는 클라이언트 측 전용이기 때문에, 이 함수는 LocalScript 에서만 사용할 수 있습니다.

참조하세요:


반환

우선 순위에 따라 GUI 탐색에 사용할 수 있는 배열 UserInputTypes 의 순서가 내림차순입니다.

GetStringForKeyCode

GetStringForKeyCode 는 사용자가 입력해야 하는 특정 Enum.KeyCode를 입력하기 위해 누르는 키를 나타내는 문자열을 반환하며, 키보드 레이아웃을 고려합니다.일부 수정자를 유지해야 하는 키 코드의 경우 이 함수는 수정자 외에 키가 누르어지도록 반환합니다.자세한 설명은 아래 예제를 참조하십시오.

QWERTY 키보드 레이아웃이 아닌 Roblox를 사용할 때 키 코드는 해당하는 QWERTY 위치로 매핑됩니다.예를 들어, AZERTY 키보드에서 A 를 누르면 Enum.KeyCode.Q가 됩니다.이 매핑은 경험 UI 요소의 일치하지 않는 정보로 이어질 수 있습니다.예를 들어, "맵을 열려면 M 을 누르세요"는 AZERTY 키보드에서 정확하지 않으며, QWERTY에서 M 와 동일한 위치에 있는 "맵을 열려면 ? 을 누르세요"가 필요합니다.이 함수는 비 QWERTY 키보드 레이아웃을 사용하는 동안 누르는 실제 키를 제공하여 이 문제를 해결합니다.


local UserInputService = game:GetService("UserInputService")
local textLabel = script.Parent
local mapKey = Enum.KeyCode.M
textLabel.Text = "Press " .. UserInputService:GetStringForKeyCode(mapKey) .. " to open the map"
QWERTY 키보드의 예시

<th>반환 값</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>Enum.KeyCode.Q</code></td>
<td><code>Q</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.W</code></td>
<td><code>W</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.Equals</code></td>
<td><code>=</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.At</code></td>
<td><code>2</code> 왜냐하면 <code>@</code> 는 <kbd>Shift</kbd><kbd>2</kbd> 타이핑되어 있기 때문입니다</td>
</tr>
</tbody>
키 코드
AZERTY 키보드의 예시

<th>반환 값</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>Enum.KeyCode.Q</code></td>
<td><code>A</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.W</code></td>
<td><code>Z</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.Equals</code></td>
<td><code>=</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.At</code></td>
<td><code>É</code></td>
</tr>
</tbody>
키 코드
게임패드 사용

는 가장 최근에 연결된 게임패드에 대한 문자열 매핑을 반환합니다.연결된 컨트롤러가 지원되지 않으면 함수는 요청된 키 코드에 대한 기본 문자열 변환을 반환합니다.

다음 예제에서는 사용자 지정 자산을 ButtonA에 매핑하는 방법을 보여줍니다.


local UserInputService = game:GetService("UserInputService")
local imageLabel = script.Parent
local key = Enum.KeyCode.ButtonA
local mappings = {
ButtonA = "rbxasset://BUTTON_A_ASSET", -- Replace with the desired ButtonA asset
ButtonCross = "rbxasset://BUTTON_CROSS_ASSET" -- Replace with the desired ButtonCross asset
}
local mappedKey = UserInputService:GetStringForKeyCode(key)
local image = mappings[mappedKey]
imageLabel.Image = image
게임패드 매핑

방향 패드 키 코드는 장치에 따라 차이가 없습니다.Enum.KeyCode.ButtonSelect는 일부 경우 약간 다른 동작을 합니다.PlayStation 매핑 둘 다 사용하여 사용자가 올바른 버튼을 볼 수 있도록 합니다.


<th>플레이스테이션 반환 값</th>
<th>Xbox 반환 값</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>Enum.KeyCode.ButtonA</code></td>
<td><code>버튼 크로스</code></td>
<td><code>버튼A</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonB</code></td>
<td><code>버튼 서클</code></td>
<td><code>버튼B</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonX</code></td>
<td><code>버튼 스퀘어</code></td>
<td><code>버튼X</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonY</code></td>
<td><code>버튼 트라이앵글</code></td>
<td><code>버튼Y</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonL1</code></td>
<td><code>버튼L1</code></td>
<td><code>버튼LB</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonL2</code></td>
<td><code>버튼L2</code></td>
<td><code>버튼LT</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonL3</code></td>
<td><code>버튼L3</code></td>
<td><code>버튼LS</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonR1</code></td>
<td><code>버튼R1</code></td>
<td><code>버튼RB</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonR2</code></td>
<td><code>버튼R2</code></td>
<td><code>버튼RT</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonR3</code></td>
<td><code>버튼R3</code></td>
<td><code>버튼RS</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonStart</code></td>
<td><code>버튼옵션</code></td>
<td><code>버튼 시작</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonSelect</code></td>
<td><code>버튼 터치패드</code> 및 <code>버튼 공유</code></td>
<td><code>버튼 선택</code></td>
</tr>
</tbody>
키 코드
키 코드용 시스템 이미지

사용자 인터페이스에서 Enum.KeyCode 처럼 이미지로 더 잘 나타낼 수 있는 ImageLabel 를 사용할 때 레거시 아이콘을 사용할 수 있습니다.그러나 Xbox 및 PlayStation 컨트롤러 아이콘을 검색하기 위한 더 현대적이고 크로스 플랫폼 방법으로 GetImageForKeyCode()를 사용하는 것이 좋습니다.


<th>이미지</th>
<th>자산 ID</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>Enum.KeyCode.ButtonX</code></td>
<td>
<img src="../../../assets/scripting/controls/xboxX.png" width="24">
</img>
</td>
<td><code>rbxasset://textures/ui/Controls/xboxX.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonY</code></td>
<td>
<img src="../../../assets/scripting/controls/xboxY.png" width="24">
</img>
</td>
<td><code>rbxasset://textures/ui/Controls/xboxY.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonA</code></td>
<td>
<img src="../../../assets/scripting/controls/xboxA.png" width="24">
</img>
</td>
<td><code>rbxasset://textures/ui/Controls/xboxA.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonB</code></td>
<td>
<img src="../../../assets/scripting/controls/xboxB.png" width="24">
</img>
</td>
<td><code>rbxasset://textures/ui/Controls/xboxB.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.DPadLeft</code></td>
<td>
<img src="../../../assets/scripting/controls/dpadLeft.png" width="24">
</img>
</td>
<td><code>rbxasset://textures/ui/Controls/dpadLeft.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.DPadRight</code></td>
<td>
<img src="../../../assets/scripting/controls/dpadRight.png" width="24">
</img>
</td>
<td><code>rbxasset://textures/ui/Controls/dpadRight.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.DPadUp</code></td>
<td>
<img src="../../../assets/scripting/controls/dpadUp.png" width="24">
</img>
</td>
<td><code>rbxasset://textures/ui/Controls/dpadUp.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.DPadDown</code></td>
<td>
<img src="../../../assets/scripting/controls/dpadDown.png" width="24">
</img>
</td>
<td><code>rbxasset://textures/ui/Controls/dpadDown.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonSelect</code></td>
<td>
<img src="../../../assets/scripting/controls/xboxView.png" width="24">
</img>
</td>
<td><code>rbxasset://textures/ui/Controls/xboxView.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonStart</code></td>
<td>
<img src="../../../assets/scripting/controls/xboxmenu.png" width="24">
</img>
</td>
<td><code>rbxasset://textures/ui/Controls/xboxmenu.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonL1</code></td>
<td>
<img src="../../../assets/scripting/controls/xboxLB.png" width="24">
</img>
</td>
<td><code>rbxasset://textures/ui/Controls/xboxLB.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonR1</code></td>
<td>
<img src="../../../assets/scripting/controls/xboxRB.png" width="24">
</img>
</td>
<td><code>rbxasset://textures/ui/Controls/xboxRB.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonL2</code></td>
<td>
<img src="../../../assets/scripting/controls/xboxLT.png" width="24">
</img>
</td>
<td><code>rbxasset://textures/ui/Controls/xboxLT.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonR2</code></td>
<td>
<img src="../../../assets/scripting/controls/xboxRT.png" width="24">
</img>
</td>
<td><code>rbxasset://textures/ui/Controls/xboxRT.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonL3</code></td>
<td>
<img src="../../../assets/scripting/controls/xboxLS.png" width="24">
</img>
</td>
<td><code>rbxasset://textures/ui/Controls/xboxLS.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.ButtonR3</code></td>
<td>
<img src="../../../assets/scripting/controls/xboxRS.png" width="24">
</img>
</td>
<td><code>rbxasset://textures/ui/Controls/xboxRS.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.Thumbstick1</code></td>
<td>
<img src="../../../assets/scripting/controls/xboxLSDirectional.png" width="24">
</img>
</td>
<td><code>rbxasset://textures/ui/Controls/xboxLSDirectional.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.Thumbstick2</code></td>
<td>
<img src="../../../assets/scripting/controls/xboxRSDirectional.png" width="24">
</img>
</td>
<td><code>rbxasset://textures/ui/Controls/xboxRSDirectional.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.백스페이스</code></td>
<td>
<img src="../../../assets/scripting/controls/backspace.png" width="24">
</img>
</td>
<td><code>rbxasset://textures/ui/Controls/백스페이스.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.Return</code></td>
<td>
<img src="../../../assets/scripting/controls/return.png" width="24">
</img>
</td>
<td><code>rbxasset://textures/ui/Controls/return.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.LeftShift</code></td>
<td>
<img src="../../../assets/scripting/controls/shift.png" width="24">
</img>
</td>
<td><code>rbxasset://textures/ui/Controls/shift.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.RightShift</code></td>
<td>
<img src="../../../assets/scripting/controls/shift.png" width="24">
</img>
</td>
<td><code>rbxasset://textures/ui/Controls/shift.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.Tab</code></td>
<td>
<img src="../../../assets/scripting/controls/tab.png" width="24">
</img>
</td>
<td><code>rbxasset://textures/ui/Controls/tab.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.Quote</code></td>
<td>
<img src="../../../assets/scripting/controls/apostrophe.png" width="24">
</img>
</td>
<td><code>rbxasset://textures/ui/Controls/아포스트로피.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.Comma</code></td>
<td>
<img src="../../../assets/scripting/controls/comma.png" width="24">
</img>
</td>
<td><code>rbxasset://textures/ui/Controls/comma.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.Backquote</code></td>
<td>
<img src="../../../assets/scripting/controls/graveaccent.png" width="24">
</img>
</td>
<td><code>rbxasset://textures/ui/Controls/graveaccent.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.Period</code></td>
<td>
<img src="../../../assets/scripting/controls/period.png" width="24">
</img>
</td>
<td><code>rbxasset://textures/ui/Controls/period.png</code></td>
</tr>
<tr>
<td><code>Enum.KeyCode.Space</code></td>
<td>
<img src="../../../assets/scripting/controls/spacebar.png" width="24">
</img>
</td>
<td><code>rbxasset://textures/ui/Controls/spacebar.png</code></td>
</tr>
</tbody>
키 코드

매개 변수

keyCode: Enum.KeyCode
기본값: ""

반환

GetSupportedGamepadKeyCodes

이 함수는 지정된 Enum.UserInputType와 연결된 게임패드에서 지원하는 배열의 KeyCodes를 반환합니다.

이 함수는 연결된 게임패드에서 지원되지 않고 지원되는 키 코드를 결정하는 데 사용할 수 있습니다.특정 KeyCode가 지원되는지 여부를 확인하려면 UserInputService:GamepadSupports()를 사용하십시오.

존재하지 않거나 연결되지 않은 게임패드에 호출되면 이 함수는 빈 배열을 반환합니다.

클라이언트 측만 있는 As UserInputService는 이 함수를 LocalScript에서만 사용할 수 있습니다.

참조하세요:

매개 변수

gamepadNum: Enum.UserInputType

게임패드의 Enum.UserInputType .

기본값: ""

반환

지정된 게임패드에서 지원하는 배열 KeyCodes.

코드 샘플

이 예제에서는 탐색 게임패드 목록과 지원되는 Enum.KeyCodes 목록을 가져옵니다.그런 다음 지원되는 KeyCode 목록을 반복하고 ButtonX 및 X 키를 게임패드를 사용하여 지원되는 경우 함수에 바인딩합니다.

바인딩 지원 게임패드 키 매핑

local UserInputService = game:GetService("UserInputService")
local ContextActionService = game:GetService("ContextActionService")
local function actionHandler(actionName, inputState, inputObject)
if inputState == Enum.UserInputState.Begin then
print("Action Handler: " .. actionName)
print(inputObject)
end
-- 이 함수는 아무것도 반환하지 않으므로 이 처리기는
-- 입력을 "싱크"하고 다른 입력 처리기가 호출되지 않습니다:"sink" the input and no other action handlers will be called after
-- 이거 하나.
end
local navGamepads = UserInputService:GetNavigationGamepads()
for _, gamepad in pairs(navGamepads) do
local supportedKeyCodes = UserInputService:GetSupportedGamepadKeyCodes(gamepad)
for _, keycode in pairs(supportedKeyCodes) do
if keycode == Enum.KeyCode.ButtonX then
ContextActionService:BindAction("SampleAction", actionHandler, false, Enum.KeyCode.ButtonX)
end
if keycode == Enum.KeyCode.X then
ContextActionService:BindAction("SampleAction", actionHandler, false, Enum.KeyCode.X)
end
end
end

IsGamepadButtonDown

이 함수는 특정 게임패드에서 특정 버튼이 누르는지 확인합니다.그것은 true 를 반환하며, gamepad 가 지정된 button 을 누르면 거짓을 반환하고, 그렇지 않으면 false를 반환합니다.

유효한 사용자 입력 유형

지정된 게임패드는 다음 UserInputType 열거형 값 중 하나여야 합니다:


<tr>
<td>Enum.UserInputType.Gamepad1-8</td>
</tr>
이름
유효한 키 코드

지정된 버튼은 다음 KeyCodes 열거형 값 중 하나여야 합니다:


<tr>
<td>Enum.KeyCode.ButtonX</td>
</tr>
<tr>
<td>Enum.KeyCode.ButtonY</td>
</tr>
<tr>
<td>Enum.KeyCode.ButtonA</td>
</tr>
<tr>
<td>Enum.KeyCode.ButtonB</td>
</tr>
<tr>
<td>Enum.KeyCode.ButtonR1</td>
</tr>
<tr>
<td>Enum.KeyCode.ButtonL1</td>
</tr>
<tr>
<td>Enum.KeyCode.ButtonR2</td>
</tr>
<tr>
<td>Enum.KeyCode.ButtonL2</td>
</tr>
<tr>
<td>Enum.KeyCode.ButtonR3</td>
</tr>
<tr>
<td>Enum.KeyCode.ButtonL3</td>
</tr>
<tr>
<td>Enum.KeyCode.ButtonStart</td>
</tr>
<tr>
<td>Enum.KeyCode.ButtonSelect</td>
</tr>
<tr>
<td>Enum.KeyCode.DPadLeft</td>
</tr>
<tr>
<td>Enum.KeyCode.DPadRight</td>
</tr>
<tr>
<td>Enum.KeyCode.DPadUp</td>
</tr>
<tr>
<td>Enum.KeyCode.DPadDown</td>
</tr>
이름

예를 들어 A와 같은 특정 버튼이 누르혀 있는지 확인하기 위해 사용할 수 있습니다. 예:


local UserInputService = game:GetService("UserInputService")
local button = Enum.KeyCode.ButtonA
local gamepad = Enum.UserInputType.Gamepad1
local isButtonHeld = UserInputService:IsGamepadButtonDown(gamepad, button)

Since UserInputService 는 클라이언트 측 전용이기 때문에, 이 함수는 LocalScript 에서만 사용할 수 있습니다.

참조하세요:

매개 변수

gamepadNum: Enum.UserInputType

지정된 게임패드의 Enum.UserInputType .

기본값: ""
gamepadKeyCode: Enum.KeyCode

지정된 버튼의 Enum.KeyCode .

기본값: ""

반환

지정된 게임패드 버튼이 누르는지 여부가 지정된 게임패드에 누르는지 여부입니다.

IsKeyDown

이 함수는 사용자가 지정된 Enum.KeyCode와 관련된 키를 길게 누르고 있는지 여부를 반환합니다.지정된 키가 누르거나 true 누르지 않으면 반환합니다.If the specified key is pressed or false 누르지 않으면 반환합니다.

예를 들어, 스페이스 바와 같은 특정 키가 누르는지 확인하기 위해 사용할 수 있습니다. 예:


local UserInputService = game:GetService("UserInputService")
local spaceHeld = UserInputService:IsKeyDown(Enum.KeyCode.Space)

사용자가 누른 모든 키 목록을 검색하려면 UserInputService:GetKeysPressed() 함수를 사용하십시오.

Since UserInputService 는 클라이언트 측 전용이기 때문에, 이 함수는 LocalScript 에서만 사용할 수 있습니다.

참조하세요:

매개 변수

keyCode: Enum.KeyCode

키의 Enum.KeyCode입니다.

기본값: ""

반환

지정된 키가 길게 누르고 있는지 여부.

IsMouseButtonPressed

이 함수는 마우스 버튼을 가져와 Enum.UserInputType 그리고 현재 누르고 있는지를 나타내는 부울을 반환합니다.

검사된 마우스 버튼은 함수에 인수로 전달된 Enum.UserInputType 값에 따라 달라집니다. 예를 들어:


local UserInputService = game:GetService("UserInputService")
local pressed = UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1)

Since UserInputService 는 클라이언트 측 전용이므로, 이 함수는 LocalScript에서만 사용할 수 있습니다."

매개 변수

mouseButton: Enum.UserInputType

마우스 버튼의 Enum.UserInputType.

기본값: ""

반환

지정된 마우스 버튼이 현재 누르고 있는지 여부.

IsNavigationGamepad

이 함수는 지정된 게임패드가 탐색 및 선택 제어를 허용하는 경우 를 반환합니다.

네비게이션 게임패드를 설정하려면 UserInputService:SetNavigationGamepad() 을 사용할 수 있습니다. 모든 네비게이션 게임패드 목록을 가져오려면 UserInputService:GetNavigationGamepads() 을 사용할 수도 있습니다.

예를 들어 아래 코드는 게임패드1이 네비게이션 게임패드인지 확인합니다:


local UserInputService = game:GetService("UserInputService")
if UserInputService:IsNavigationGamepad(UserInputType.Gamepad1) then
print("Gamepad is a navigation gamepad!")
else
print("Gamepad is not a navigation gamepad!")
end

탐색에 관계없이 모든 연결된 게임패드 목록을 `UserInput/GetConnectedGamepads`를 사용하여 검색할 수 있습니다.

Since UserInputService 는 클라이언트 측 전용이기 때문에, 이 함수는 LocalScript 에서만 사용할 수 있습니다.

참조하세요:

매개 변수

gamepadEnum: Enum.UserInputType

지정된 게임패드의 Enum.UserInputType .

기본값: ""

반환

지정된 게임패드가 네비게이션 게임패드인지 여부.

RecenterUserHeadCFrame

()

이 함수는 VR 헤드셋의 CFrame를 사용자가 착용하는 헤드셋의 현재 방향으로 재설정합니다.이는 헤드셋의 현재 방향이 CFrame.new()로 설정되었음을 의미합니다.

이 함수를 사용하여 이상한 오프셋처럼 보이는 경우 헤드셋 CFrame을 플레이 영역 중앙으로 이동합니다.

이는 VRService 함수와 동일하게 작동합니다, VRService:RecenterUserHeadCFrame().

Since UserInputService 는 클라이언트 측 전용이기 때문에, 이 함수는 LocalScript 에서만 사용할 수 있습니다.


반환

()

SetNavigationGamepad

()

SetNavigationGamepad 함수는 지정된 Enum.UserInputType 게임패드가 GUI 네비게이터를 이동할 수 있는지 여부를 설정합니다.GUI 탐색기를 이동할 수 있는 게임패드는 탐색 게임패드로 간주됩니다.

활성화 인수가 true로 전달되면 게임패드가 GUI 네비게이터를 이동할 수 있습니다.인수가 false 인 경우 Gamepad는 GUI 탐색기를 이동할 수 없습니다.

지정된 게임패드가 네비게이션 게임패드로 설정되었는지 확인하려면 UserInputService:IsNavigationGamepad() 함수를 사용할 수 있습니다.또한 UserInputService:GetNavigationGamepads()를 사용하여 모든 네비게이션 게임패드의 목록을 검색할 수 있습니다.

Since UserInputService 는 클라이언트 측 전용이기 때문에, 이 함수는 LocalScript 에서만 사용할 수 있습니다.

참조하세요:

매개 변수

gamepadEnum: Enum.UserInputType

지정된 게임패드의 Enum.UserInputType .

기본값: ""
enabled: boolean

지정된 게임패드가 GUI 네비게이터를 이동할 수 있는지 여부.

기본값: ""

반환

()

코드 샘플

이 예제에서는 탐색 게임패드로 Gamepad1를 설정하여 Enum.UserInputType.Gamepad1true를 인수로 전달합니다.

사용자 입력 서비스: 네비게이션 게임패드 설정

local UserInputService = game:GetService("UserInputService")
UserInputService:SetNavigationGamepad(Enum.UserInputType.Gamepad1, true)

이벤트

DeviceAccelerationChanged

장치 가속 변경 이벤트는 사용자가 가속도 센서가 있는 장치를 이동할 때 발생합니다.

가속도계는 가속(속도 변화)을 측정하는 대부분의 모바일 장치에서 찾을 수 있는 구성 요소입니다.

사용자의 장치에 가속기가 활성화되었는지 여부를 확인하려면 UserInputService.AccelerometerEnabled를 참조하십시오.

이 이벤트를 사용하여 가속도 센서가 있는 장치의 이동을 추적할 수 있습니다.샘플 사용에는 모바일 장치가 가속될 때 플레이어 캐릭터를 이동하는 것이 포함됩니다.

또한, 이 이벤트는 가속기가 있는 경우 사용자의 장치의 현재 이동을 결정하기 위해 UserInputService:GetDeviceAcceleration()와 함께 사용할 수 있습니다.

이 이벤트는 로컬에서만 발생하며 - 즉, 장치가 이동하는 플레이어만 이벤트를 사용할 수 있고 작동은 LocalScript에서만 가능합니다.

매개 변수

acceleration: InputObject

InputObject , 그리고 각 로컬 장치 축에서 중력의 힘을 보여주는 UserInputType'가속도계' 와 함께, 그리고 그 힘을 보여주는 Position .


코드 샘플

This example uses the accelerometer to move the player character when a mobile device is accelerated. The character will move along the axis that the device was moved.

Control Players Using the Accelerometer

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)
end

DeviceGravityChanged

장치의 중력 UserInputService.DeviceGravityChanged 이 가속기가 있는 장치에서 변경될 때 이벤트가 발생합니다.The 장치의 중력 Vector3 이벤트 발생 when the device's gravity 변경됩니다 on a device that has an accelerometer.

장치의 중력 벡터는 각 장치의 X, Y 및 Z축에서 중력의 힘을 나타냅니다.중력은 결코 변하지 않지만, 장치가 회전하고 방향을 변경할 때 각 축에 가하는 힘이 변합니다.각 축에 가해지는 힘 값은 -1에서 1 사이의 단위 벡터입니다.

가속도계는 가속(속도 변화)을 측정하는 대부분의 모바일 장치에서 찾을 수 있는 구성 요소입니다.

이 이벤트는 사용자 장치에서 중력의 실제 방향을 결정하는 데 사용할 수 있습니다.이를 통해 게임 내 개체(아래 예제 참조)와 같이 사용자 장치에서 중력의 힘을 시뮬레이션할 수도 있습니다.

사용자의 장치에 가속도계가 활성화되어 있는지 확인하려면 UserInputService.AccelerometerEnabled를 참조하십시오.장치에 가속기가 활성화되어 있으면 UserInputService:GetDeviceGravity() 함수를 사용하여 사용자 장치의 현재 중력 힘을 가져올 수 있습니다.

매개 변수

gravity: InputObject

각 로컬 장치 축에서 중력의 힘을 보여 주는 InputObject 속성이 있는 InputObject.Position 속성.이 위치는 장치에 대한 중력 방향을 결정하는 방향으로 사용할 수 있습니다.


코드 샘플

This code adds a force on a part so that it falls in the direction of actual gravity relative to the user's device. In order for this example to work as expected, it must be placed in a LocalScript and the user's device must have an accelerometer.

Move a Ball using the Accelerometer

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)
end

DeviceRotationChanged

기기 회전 변경 이벤트는 사용자가 자이로스코프가 있는 장치를 회전할 때 발생합니다.

자이로스코프는 방향과 회전 속도를 감지하는 대부분의 모바일 장치에서 찾을 수 있는 구성 요소입니다.

이벤트는 장치의 방향과 사용자가 장치를 회전할 때 변경되는 방법을 추적하는 데 유용합니다.현재 장치 회전을 결정하려면 UserInputService:GetDeviceRotation() 함수를 사용할 수 있습니다.

사용자의 장치에 자이로스코프가 활성화되어 있는지 확인하고, 이 이벤트가 발생할지 여부를 확인하려면 UserInputService.GyroscopeEnabled를 참조하십시오.

이 이벤트는 Roblox 클라이언트 창이 포커스에 있을 때만 발생합니다. 예를 들어, 창이 최소화되면 입력이 캡처되지 않습니다.

매개 변수

rotation: InputObject

장치의 회전에 대한 정보를 제공하는 InputObject 입니다. 는 새로운 회전을 나타내며, 는 위치 값에서의 회전 변경을 나타내고, 는 위치 값에서의 회전 변경을 나타냅니다.

cframe: CFrame

장치의 현재 방향을 나타내는 A CFrame입니다.


코드 샘플

This code adds a force on a part so that it falls in the direction of actual gravity relative to the user's device. In order for this example to work as expected, it must be placed in a LocalScript and the user's device must have an accelerometer.

Move a Ball using the Accelerometer

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)
end

GamepadConnected

게임패드 연결 이벤트는 게임패드가 클라이언트에 연결되면 발생합니다.

Roblox 게임이 여러 컨트롤러를 지원하기 때문에, 이 이벤트는 활성 컨트롤러/게임패드를 추적하기 위해 UserInputService.GamepadDisconnected 이벤트와 페어링할 때 유용합니다.또한 UserInputService:GetConnectedGamepads()를 사용하여 사용할 올바른 게임패드를 찾을 수 있습니다.

다음 예제에서는 게임패드가 클라이언트에 연결되었을 때의 추적 사용 예를 보여줍니다.


local UserInputService = game:GetService("UserInputService")
local function GamepadConnected(gamepad)
print("Player has plugged controller: " .. tostring(gamepad))
end)
UserInputService.GamepadConnected:Connect(GamepadConnected)

연결된 장치를 보려면 UserInputService:GetConnectedGamepads() 함수를 사용할 수 있습니다.

이 이벤트가 로컬로 발생하기 때문에, 이를 LocalScript에서만 사용할 수 있습니다.

참조하세요:

매개 변수

gamepadNum: Enum.UserInputType

연결된 게임패드의 Enum.UserInputType .


GamepadDisconnected

게임패드 연결 해제 이벤트는 게임패드가 연결 해제될 때 발생합니다.

Roblox 게임이 여러 컨트롤러를 지원하기 때문에, 이 이벤트는 활성 컨트롤러/게임패드를 추적하기 위해 UserInputService.GamepadConnected 이벤트와 페어링할 때 유용합니다.또한 UserInputService:GetConnectedGamepads()를 사용하여 사용할 올바른 게임패드를 찾을 수 있습니다.

다음 예제에서는 게임패드가 클라이언트에서 연결 해제될 때의 추적 사용 예를 보여줍니다.


local UserInputService = game:GetService("UserInputService")
local function GamepadDisconnected(gamepad)
print("Player has unplugged controller: " .. tostring(gamepad))
end)
UserInputService.GamepadDisconnected:Connect(GamepadDisconnected)

이 이벤트가 로컬로 발생하기 때문에, 이를 LocalScript에서만 사용할 수 있습니다.

참조하세요:

매개 변수

gamepadNum: Enum.UserInputType

연결이 끊어진 게임패드의 Enum.UserInputType입니다.


InputBegan

입력 시작 이벤트는 사용자가 인간-컴퓨터 인터페이스 장치(마우스 버튼 아래, 터치 시작, 키보드 버튼 아래 등)를 통해 상호 작용을 시작할 때 발생합니다.

사용자가 GUI 요소, 게임패드 등과 처음 상호작용할 때 사용자 상호작용의 시작을 추적하는 데 사용할 수 있습니다.마우스 휠 이동은 캡처하지 않습니다.

이 이벤트는 UserInputService.InputChangedUserInputService.InputEnded와 함께 사용하여 사용자 입력이 시작되고, 변경되고, 종료될 때를 추적할 수 있습니다.

이 이벤트는 Roblox 클라이언트 창이 포커스에 있을 때만 발생합니다. 예를 들어, 창이 최소화되면 입력이 캡처되지 않습니다.

이 이벤트는 로컬에서만 발생하므로 LocalScript 에서만 사용할 수 있습니다.

매개 변수

사용자의 입력에 대한 정보가 포함된 InputObject 인스턴스.

gameProcessedEvent: boolean

게임 엔진이 내부적으로 이 입력을 관찰하고 조작했는지 여부를 나타냅니다.일반적으로 이는 UI 처리를 의미하므로 이 입력에서 버튼이 터치되거나 클릭되면 gameProcessedEventtrue 가 됩니다.이는 또한 ContextActionService를 통해 연결된 입력 이벤트에도 적용됩니다.


코드 샘플

다음 예제에서는 입력 시작의 유형에 따라 다양한 사용 예제 중 하나를 처리하는 방법을 보여줍니다.

입력 처리 시작

-- 입력 시작 이벤트를 사용하려면 UserInputService 서비스를 사용해야 합니다
local UserInputService = game:GetService("UserInputService")
-- 다양한 유형의 사용자 입력에 대한 여러 사용 사례를 제공하는 샘플 함수
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if input.UserInputType == Enum.UserInputType.Keyboard then
print("A key is being pushed down! Key:", input.KeyCode)
elseif input.UserInputType == Enum.UserInputType.MouseButton1 then
print("The left mouse button has been pressed down at", input.Position)
elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
print("The right mouse button has been pressed down at", input.Position)
elseif input.UserInputType == Enum.UserInputType.Touch then
print("A touchscreen input has started at", input.Position)
elseif input.UserInputType == Enum.UserInputType.Gamepad1 then
print("A button is being pressed on a gamepad! Button:", input.KeyCode)
end
if gameProcessed then
print("The game engine internally observed this input!")
else
print("The game engine did not internally observe this input!")
end
end)

InputChanged

입력 변경 이벤트는 사용자가 인간-컴퓨터 인터페이스 장치(마우스 버튼 아래, 터치 시작, 키보드 버튼 아래 등)를 통해 상호 작용하는 방식을 변경할 때 발생합니다.

Roblox에서 자동으로 처리하는 이벤트를 무시하려면, ScrollingFrame에서 스크롤과 같이, gameProcessedEvent 인수가 false인지 확인하십시오.이 이벤트는 UserInputService.InputBeganUserInputService.InputEnded과 함께 사용하여 사용자 입력이 시작되고, 변경되고, 종료될 때를 추적할 수 있습니다.

이 이벤트는 Roblox 클라이언트 창이 포커스에 있을 때만 발생합니다. 예를 들어, 창이 최소화되면 입력이 캡처되지 않습니다.

이 이벤트는 로컬에서만 발생하므로 LocalScript 에서만 사용할 수 있습니다.

매개 변수

사용자의 입력에 대한 정보가 포함된 InputObject 인스턴스.

gameProcessedEvent: boolean

게임 엔진이 내부적으로 이 입력을 관찰하고 조작했는지 여부를 나타냅니다.일반적으로 이는 UI 처리를 의미하므로 이 입력에서 버튼이 터치되거나 클릭되면 gameProcessedEventtrue 가 됩니다.이는 또한 ContextActionService를 통해 연결된 입력 이벤트에도 적용됩니다.


InputEnded

입력 종료 이벤트는 사용자가 인간-컴퓨터 인터페이스 장치(마우스 버튼 아래로, 터치 시작, 키보드 버튼 아래로 등)를 통해 상호 작용을 중단할 때 발생합니다.사용자가 키보드 키, 마우스 버튼, 터치스크린 입력 등을 릴리스할 때 추적하는 데 유용합니다.

이 이벤트는 UserInputService.InputBeganUserInputService.InputChanged와 함께 사용하여 사용자 입력이 시작되고, 변경되고, 종료될 때를 추적할 수 있습니다.

이 이벤트는 Roblox 클라이언트 창이 포커스에 있을 때만 발생합니다. 예를 들어, 창이 최소화되면 입력이 캡처되지 않습니다.

이 이벤트는 로컬에서만 발생하므로 LocalScript 에서만 사용할 수 있습니다.

매개 변수

사용자 입력에 대한 정보가 포함된 InputObject 인스턴스.

gameProcessedEvent: boolean

게임 엔진이 내부적으로 이 입력을 관찰하고 조작했는지 여부를 나타냅니다.일반적으로 이는 UI 처리를 의미하므로 이 입력에서 버튼이 터치되거나 클릭되면 gameProcessedEventtrue 가 됩니다.이는 또한 ContextActionService를 통해 연결된 입력 이벤트에도 적용됩니다.


JumpRequest

클라이언트가 공백을 누르거나 모바일에서 점프 버튼을 누른 경우와 같이 클라이언트에서 점프 요청이 발생하면 UserInputService 점프 요청 이벤트가 발생합니다.

이 이벤트는 사용자가 자신의 Player.Character 점프를 시도할 때마다 발생합니다.기본 동작은 점프 요청에 응답하여 플레이어의 Humanoid.Jump 속성을 true로 설정하여 플레이어의 캐릭터가 점프하도록 합니다.

이벤트를 사용하여 플레이어가 점프하고 싶을 때마다 추적할 수 있습니다.플레이어를 점프시키는 데 사용하는 대신, 이 기능은 기본 점프 동작을 변경하는 데 사용되어야 합니다(예: 점프 비활성화).

예를 들어, 아래 코드는 플레이어가 점프 요청을 보낼 때마다 "점프"를 출력합니다.


local UserInputService = game:GetService("UserInputService")
function onJumpRequest()
print("Jump!")
end
UserInputService.JumpRequest:Connect(onJumpRequest)

이 이벤트는 단일 점프 요청에 대해 여러 번 발생하므로, debounce를 사용하는 것이 좋습니다.

키 또는 버튼을 다른 작업에 연결하려는 경우 UserInputService:GetKeysPressed() 또는 UserInputService.InputBegan 또는 ContextActionService와 같은 이벤트를 사용하는 것을 고려하십시오.

이 이벤트는 로컬에서만 발생하므로 LocalScript 에서만 사용할 수 있습니다.


코드 샘플

이 코드 샘플은 상태 를 false로 설정하여 점프를 비활성화합니다.사용자가 점프를 취소하려고 하면 이 상태를 false로 설정하여 점프를 취소합니다.

이 예제가 예상대로 작동하려면 LocalScript 에 배치되어야 합니다.

점프 비활성화

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")
-- 사용자가 점프하려고 할 때 발생하는 화재
local function jump()
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
end
UserInputService.JumpRequest:Connect(jump)

LastInputTypeChanged

클라이언트가 인간-컴퓨터 인터페이스 장치를 통해 상호 작용하는 방식을 변경할 때마다 UserInputService.LastInputTypeChanged 이벤트가 발생합니다.(i.e.마우스 이동에서 마우스 휠로 또는 썸스틱1에서 썸스틱2로(from MouseMovement to MouseWheel or from Thumbstick1 to Thumbstick2).

변경되었는지 여부에 관계없이 마지막 입력 유형의 값을 가져오려면 UserInputService:GetLastInputType() 함수를 사용할 수 있습니다.

이 이벤트는 로컬에서만 발생하므로 LocalScript 에서만 사용할 수 있습니다.

매개 변수

lastInputType: Enum.UserInputType

마지막 입력 유형을 나타내는 A Enum.UserInputType


코드 샘플

This example hides the mouse icon while the player beings using their keyboard, such as to chat or enter text into a TextBox. The mouse icon reappears when the user resumes mouse input.

This uses the LastInputType() event to determine when the user begins keyboard input and mouse input - based on the value of the lastInputType argument.

In order for this example to work as expected, it should be placed in a LocalScript.

Hide Mouse During Keyboard Input

local UserInputService = game:GetService("UserInputService")
local mouseInput = {
Enum.UserInputType.MouseButton1,
Enum.UserInputType.MouseButton2,
Enum.UserInputType.MouseButton3,
Enum.UserInputType.MouseMovement,
Enum.UserInputType.MouseWheel,
}
local keyboard = Enum.UserInputType.Keyboard
local function toggleMouse(lastInputType)
if lastInputType == keyboard then
UserInputService.MouseIconEnabled = false
return
end
for _, mouse in pairs(mouseInput) do
if lastInputType == mouse then
UserInputService.MouseIconEnabled = true
return
end
end
end
UserInputService.LastInputTypeChanged:Connect(toggleMouse)

PointerAction

포인터 액션 사용자가 특정 포인터 작업을 수행할 때 발생합니다. 특히 마우스 휠을 스크롤합니다.

매개 변수

wheel: number
pan: Vector2
pinch: number
gameProcessedEvent: boolean

TextBoxFocusReleased

클라이언트가 에 집중을 잃을 때 이벤트가 발생하며, 일반적으로 클라이언트가 반환을 누르거나 화면의 다른 곳을 클릭/터치하여 텍스트 입력을 중지할 때입니다.

예를 들어 아래 코드는 이벤트가 발생할 때 포커스를 잃는 TextBox 이름을 출력합니다.


local UserInputService = game:GetService("UserInputService")
function TextBoxFocusReleased(textbox)
print(textbox.Name)
end
UserInputService.TextBoxFocusReleased:Connect(TextBoxFocusReleased)

그것은 UserInputService.TextBoxFocused 와 함께 사용하여 언제 TextBox 가 초점을 얻고 잃는지 추적할 수 있습니다.

이 이벤트는 로컬에서만 발생하므로 LocalScript 에서만 사용할 수 있습니다.

또한 참조하세요

매개 변수

textboxReleased: TextBox

초점을 잃은 TextBox .


TextBoxFocused

이 이벤트는 클라이언트가 텍스트 상자를 클릭하거나 탭하여 텍스트 입력을 시작할 때 TextBox에 초점을 맞추면 발생합니다.또한 텍스트 상자 포커스가 TextBox:CaptureFocus()를 사용하여 포커스가 되면 발생합니다.

예를 들어 아래 코드는 이벤트가 발생할 때 초점이 된 TextBox의 이름을 출력합니다.


local UserInputService = game:GetService("UserInputService")
function TextBoxFocused(textbox)
print(textbox.Name)
end)
UserInputService.TextBoxFocused:Connect(TextBoxFocused)

텍스트 상자가 초점을 얻고 잃을 때를 추적하기 위해 UserInputService.FocusReleased와 함께 사용할 수 있습니다.

이 이벤트는 로컬에서만 발생하므로 LocalScript 에서만 사용할 수 있습니다.

또한 참조하세요

매개 변수

textboxFocused: TextBox

초점을 얻은 TextBox 입니다.


TouchDrag

매개 변수

dragDirection: Enum.SwipeDirection
numberOfTouches: number
gameProcessedEvent: boolean

TouchEnded

터치 종료 이벤트는 사용자가 터치 활성화된 장치의 화면에서 손가락을 놓아 터치 입력을 장치로 종료할 때 발생합니다.

이 이벤트를 사용하여 사용자가 장치의 화면을 더 이상 터치하지 않는 시기를 결정할 수 있습니다.사용자가 화면을 만지기 시작하고 중지하는 시기를 결정하기 위해 UserInputService.TouchStarted와 쌍을 이룰 수 있습니다.

예를 들어 아래 코드는 사용자가 화면을 만지기를 중지하는 화면 위치를 인쇄합니다.


local UserInputService = game:GetService("UserInputService")
function TouchEnded(touch, gameProcessedEvent)
print("Touch ended at " .. tostring(touch.Position))
end
UserInputService.TouchEnded:Connect(TouchEnded)

터치 입력 개체는 터치의 수명 동안 동일한 입력 개체입니다.따라서 터치 개체인 경우 InputObjects를 비교하여 동일한 손가락인지 확인할 수 있습니다.

사용자의 장치가 TouchEnabled인지 확인하고 터치 이벤트가 발생하는지 보려면 UserInputService.TouchEnabled를 참조하십시오.

이 이벤트는 Roblox 클라이언트 창이 포커스에 있을 때만 발생합니다. 예를 들어, 창이 최소화되면 입력이 캡처되지 않습니다.

이 이벤트는 로컬에서만 발생하므로 LocalScript 에서만 사용할 수 있습니다.

참조하세요:

매개 변수

사용자의 입력에 대한 정보가 포함된 InputObject 인스턴스.

gameProcessedEvent: boolean

게임 엔진이 내부적으로 이 입력을 관찰하고 조작했는지 여부를 나타냅니다.일반적으로 이는 UI 처리를 의미하므로 이 입력에서 버튼이 터치되거나 클릭되면 gameProcessedEventtrue 가 됩니다.이는 또한 ContextActionService를 통해 연결된 입력 이벤트에도 적용됩니다.


TouchLongPress

사용자가 터치 활성화된 장치의 동일한 화면 위치에서 짧은 시간 동안 최소 하나의 손가락을 누르는 경우 발사됩니다.

이 이벤트는 사용자가 게임 내 GuiObject 또는 요소에 손가락을 누르고 있는 시기를 결정하는 데 사용할 수 있습니다.

아래 예제는 사용자가 같은 화면 위치에서 짧은 시간 동안 한 손가락을 길게 누르는 경우 state 를 인쇄합니다.가능한 상태에는: 시작, 변경, 종료, 취소, 및 없음이 포함됩니다.


local UserInputService = game:GetService("UserInputService")
function TouchLongPress(TouchPositions, state, gameProcessedEvent)
print("Long press event fired. State of press: " .. tostring(state))
end
UserInputService.TouchLongPress:Connect(TouchLongPress)

사용자의 장치가 TouchEnabled인지 확인하고 터치 이벤트가 발생하는지 보려면 UserInputService.TouchEnabled를 참조하십시오.

사용자가 화면을 터치하기 시작하고 중지하는 시기를 결정하기 위해 UserInputService.TouchStartedUserInputService.TouchEnded와 쌍을 이룰 수 있습니다.

이 이벤트는 Roblox 클라이언트 창이 포커스에 있을 때만 발생합니다. 예를 들어, 창이 최소화되면 입력이 캡처되지 않습니다.

이 이벤트는 로컬에서만 발생하므로 LocalScript 에서만 사용할 수 있습니다.

참조하세요:

매개 변수

touchPositions: Array

제스처에 관여하는 손가락의 위치를 나타내는 배열의 Vector2 개체.

제스처의 Enum.UserInputState입니다.

gameProcessedEvent: boolean

게임 엔진이 내부적으로 이 입력을 관찰하고 조작했는지 여부를 나타냅니다.일반적으로 이는 UI 처리를 의미하므로 이 입력에서 버튼이 터치되거나 클릭되면 gameProcessedEventtrue 가 됩니다.이는 또한 ContextActionService를 통해 연결된 입력 이벤트에도 적용됩니다.


TouchMoved

태블릿이나 스마트폰과 같은 장치에서 사용자가 손가락을 이동할 때 발생하는 화재TouchEnabled

이 이벤트는 사용자가 화면에서 손가락을 이동하는지 여부와 사용자가 손가락을 이동하는 위치를 추적하는 데 유용합니다.

아래 코드는 터치가 이전 위치에서 새로운 위치로 이동하는 것을 보여줍니다 TouchEnabled 장치.패스된 InputObject.Position 매개 변수의 touch 에 있는 노트는 Vector3 이지만 X와 Y 좌표만 포함됩니다; Z는 항상 0입니다.


local UserInputService = game:GetService("UserInputService")
function onTouchMoved(touch, gameProcessedEvent)
local oldPosition = touch.Position - touch.Delta
print("Touch moved from " .. tostring(oldPosition) .. " to " .. tostring(touch.Position))
end
UserInputService.TouchMoved:Connect(onTouchMoved)

이 이벤트를 UserInputService.TouchStartedUserInputService.TouchEnded와 페어링하여 사용자가 화면을 터치하기 시작하는 시기, 터치하는 동안 손가락이 이동하는 시기, 그리고 화면 터치를 중지하는 시기를 결정합니다.

사용자의 장치가 터치를 지원하고 해당 터치 이벤트가 발생하는지 확인하려면 UserInputService.TouchEnabled를 참조하십시오.

이 이벤트는 Roblox 클라이언트 창이 포커스에 있을 때만 발생합니다. 예를 들어, 창이 최소화되면 입력이 캡처되지 않습니다.

이 이벤트는 로컬에서만 발생하므로 LocalScript 에서만 사용할 수 있습니다.

참조하세요:

매개 변수

사용자의 입력에 대한 정보가 포함된 InputObject 인스턴스.

gameProcessedEvent: boolean

게임 엔진이 내부적으로 이 입력을 관찰하고 조작했는지 여부를 나타냅니다.일반적으로 이는 UI 처리를 의미하므로 이 입력에서 버튼이 터치되거나 클릭되면 gameProcessedEventtrue 가 됩니다.이는 또한 ContextActionService를 통해 연결된 입력 이벤트에도 적용됩니다.


TouchPan

터치패널 이벤트는 사용자가 장치에서 최소 하나의 손가락을 드래그할 때 발생합니다.The TouchPan event fires when a user drags at least one finger on a TouchEnabled device.

이 이벤트는 사용자가 터치 활성화된 장치의 화면에서 손가락을 스크롤할 때를 결정하는 데 사용할 수 있습니다. - 예를 들어, 사용자가 사용자 정의 카메라 스크립트에서 회전하는 Camera를 회전하기 위해.

아래 코드는 "터치 드래그의 속도"를 인쇄하고 사용자가 화면에서 손가락을 드래그할 때 사용자의 터치 속도를 따릅니다.


local UserInputService = game:GetService("UserInputService")
UserInputService.TouchPan:Connect(function(touchPositions, totalTranslation, velocity, state, gameProcessedEvent)
print("Speed of touch drag: " .. tostring(velocity))
end)

여기서 다른 유용한 UserInputService 함수를 살펴보세요 UserInputService.TouchRotate.

이 이벤트는 Roblox 클라이언트 창이 포커스에 있을 때만 발생합니다. 예를 들어, 창이 최소화되면 입력이 캡처되지 않습니다.

이 이벤트는 로컬에서만 발생하므로 LocalScript 에서만 사용할 수 있습니다.

참조하세요:

매개 변수

touchPositions: Array

터치(예: 손가락)가 관련된 제스처의 위치를 나타내는 배열의 Vector2 개체.

totalTranslation: Vector2

시작부터 끝까지의 팬 제스처 크기(픽셀).

velocity: Vector2

초당 팬 제스처의 속도(픽셀)입니다.

제스처의 Enum.UserInputState입니다.

gameProcessedEvent: boolean

게임 엔진이 내부적으로 이 입력을 관찰하고 조작했는지 여부를 나타냅니다.일반적으로 이는 UI 처리를 의미하므로 이 입력에서 버튼이 터치되거나 클릭되면 gameProcessedEventtrue 가 됩니다.이는 또한 ContextActionService를 통해 연결된 입력 이벤트에도 적용됩니다.


TouchPinch

사용자가 장치의 화면에 두 손가락을 배치하고 이동할 때 발사됩니다. TouchEnabled 장치.

예를 들어, 아래 코드는 터치 핀치가 시작된 이후 카메라 줌 규모가 얼마나 변경되었는지 인쇄합니다.


local UserInputService = game:GetService("UserInputService")
UserInputService.TouchPinch:Connect(function(touchPositions, scale, velocity, state, gameProcessedEvent)
print("Scale difference since beginning of pinch: " .. tostring(scale))
end)

사용자의 장치가 TouchEnabled인지 확인하고 터치 이벤트가 발생하는지 보려면 UserInputService.TouchEnabled를 참조하십시오.

이 이벤트는 Roblox 클라이언트 창이 포커스에 있을 때만 발생합니다.예를 들어, 창이 최소화되면 입력이 캡처되지 않습니다.이 이벤트는 로컬에서만 발생하므로 LocalScript 에서만 사용할 수 있습니다.

참조하세요:

매개 변수

touchPositions: Array

피칭 제스처에 참여하는 손가락의 화면 위치, 픽셀로 표시되는 배열 Vector2s .

scale: number

시작부터 끝까지의 핀치 크기(픽셀)를 시작 핀치 위치로 나눈 값입니다.

velocity: number

초당 핀치 제스처의 속도(픽셀 단위).

제스처의 Enum.UserInputState입니다.

gameProcessedEvent: boolean

게임 엔진이 내부적으로 이 입력을 관찰하고 조작했는지 여부를 나타냅니다.일반적으로 이는 UI 처리를 의미하므로 이 입력에서 버튼이 터치되거나 클릭되면 gameProcessedEventtrue 가 됩니다.이는 또한 ContextActionService를 통해 연결된 입력 이벤트에도 적용됩니다.


TouchRotate

터치 회전 이벤트는 사용자가 장치의 TouchEnabled 두 손가락을 회전할 때 발생합니다.

예를 들어 다음 코드는 터치 회전의 시작 이후 카메라가 회전한 정도를 인쇄합니다.


local UserInputService = game:GetService("UserInputService")
UserInputService.TouchRotate:Connect(function(touchPositions, rotation, velocity, state, gameProcessedEvent)
print("Camera has rotated " .. tostring(rotation) .. " degrees!")
end)

사용자의 장치가 TouchEnabled인지 확인하고 터치 이벤트가 발생하는지 보려면 UserInputService.TouchEnabled를 참조하십시오.

이 이벤트는 Roblox 클라이언트 창이 포커스에 있을 때만 발생합니다. 예를 들어, 창이 최소화되면 입력이 캡처되지 않습니다.

이 이벤트는 로컬에서만 발생하므로 LocalScript 에서만 사용할 수 있습니다.

모바일 장치에서 사용자의 카메라를 제어하는 핵심 스크립트는 이 이벤트와 유사한 기능을 수행하는 코드를 사용합니다.이 이벤트에 대한 모범 사례는 기본 코어 스크립트를 재정의하기 위해 모바일 카메라 시스템을 생성할 때 사용하는 것입니다.

참조하세요:

매개 변수

touchPositions: Array

Vector2s 배열, 제스처에 관여하는 손가락의 위치를 나타내는 배열.

rotation: number

제스처가 시작된 이후 회전된 제스처의 정도 수입니다.

velocity: number

회전 변경(도)를 변경 기간(초)으로 나눈 값입니다.

제스처의 Enum.UserInputState입니다.

gameProcessedEvent: boolean

게임 엔진이 내부적으로 이 입력을 관찰하고 조작했는지 여부를 나타냅니다.일반적으로 이는 UI 처리를 의미하므로 이 입력에서 버튼이 터치되거나 클릭되면 gameProcessedEventtrue 가 됩니다.이는 또한 ContextActionService를 통해 연결된 입력 이벤트에도 적용됩니다.


TouchStarted

터치 시작 이벤트는 사용자가 장치에 손가락을 대기 시작하면 발생하며, 장치로 터치 입력을 시작합니다.

이 이벤트를 사용하여 사용자가 장치의 화면을 터치하기 시작한 시기를 결정할 수 있습니다.사용자가 화면을 만지기 시작하고 중지하는 시기를 결정하기 위해 UserInputService.TouchEnded와 쌍을 이룰 수 있습니다.

터치 입력 개체는 터치의 수명 동안 동일한 입력 개체입니다.따라서 터치 개체인 경우 InputObjects를 비교하여 동일한 손가락인지 확인할 수 있습니다.

사용자의 장치가 TouchEnabled인지 확인하고 터치 이벤트가 발생하는지 보려면 UserInputService.TouchEnabled를 참조하십시오.

이 이벤트는 Roblox 클라이언트 창이 포커스에 있을 때만 발생합니다. 예를 들어, 창이 최소화되면 입력이 캡처되지 않습니다.

이 이벤트는 로컬에서만 발생하므로 LocalScript 에서만 사용할 수 있습니다.

참조하세요:

매개 변수

사용자의 입력에 대한 정보가 포함된 InputObject 인스턴스.

gameProcessedEvent: boolean

게임 엔진이 내부적으로 이 입력을 관찰하고 조작했는지 여부를 나타냅니다.일반적으로 이는 UI 처리를 의미하므로 이 입력에서 버튼이 터치되거나 클릭되면 gameProcessedEventtrue 가 됩니다.이는 또한 ContextActionService를 통해 연결된 입력 이벤트에도 적용됩니다.


TouchSwipe

사용자가 장치에서 손가락을 스와이프할 때 TouchSwipe 이벤트가 발생합니다.The TouchEnabled event fires when a user swipes their fingers on a 장치.

이 이벤트를 사용하여 사용자가 장치의 화면에 손가락을 쓸 때와 사용자가 쓴 방향을 결정할 수 있습니다.

터치 입력 이동을 보다 정확하게 추적하려면 UserInputService.TouchMoved를 사용하십시오

사용자의 장치가 TouchEnabled인지 확인하고 터치 이벤트가 발생하는지 보려면 UserInputService.TouchEnabled를 참조하십시오.

이 이벤트는 Roblox 클라이언트 창이 포커스에 있을 때만 발생합니다. 예를 들어, 창이 최소화되면 입력이 캡처되지 않습니다.

이 이벤트는 로컬에서만 발생하므로 LocalScript 에서만 사용할 수 있습니다.

참조하세요:

매개 변수

swipeDirection: Enum.SwipeDirection

사용자가 스와이프한 방향을 나타내는 Enum.SwipeDirection .

numberOfTouches: number

제스처에 참여하는 터치 횟수(예: 손가락).

gameProcessedEvent: boolean

게임 엔진이 내부적으로 이 입력을 관찰하고 조작했는지 여부를 나타냅니다.일반적으로 이는 UI 처리를 의미하므로 이 입력에서 버튼이 터치되거나 클릭되면 gameProcessedEventtrue 가 됩니다.이는 또한 ContextActionService를 통해 연결된 입력 이벤트에도 적용됩니다.


TouchTap

터치 이벤트는 사용자가 TouchEnabled 장치의 화면에 손가락을 터치/탭하면 발생합니다.

이 이벤트는 사용자가 게임 세계나 GuiObject 요소를 터치/탭하는지 여부에 관계없이 발생합니다.사용자가 게임 세계에 터치하거나 탭할 때만 발생하는 이벤트를 찾고 있는 경우 UserInputService.TouchTapInWorld를 사용하십시오.

사용자의 장치가 TouchEnabled인지 확인하고 터치 이벤트가 발생하는지 보려면 UserInputService.TouchEnabled를 참조하십시오.

이 이벤트는 Roblox 클라이언트 창이 포커스에 있을 때만 발생합니다. 예를 들어, 창이 최소화되면 입력이 캡처되지 않습니다.

이 이벤트는 로컬에서만 발생하므로 LocalScript 에서만 사용할 수 있습니다.

매개 변수

touchPositions: Array

탭 제스처에 관여하는 손가락의 위치를 나타내는 Vector2 개체 배열,

gameProcessedEvent: boolean

게임 엔진이 내부적으로 이 입력을 관찰하고 조작했는지 여부를 나타냅니다.일반적으로 이는 UI 처리를 의미하므로 이 입력에서 버튼이 터치되거나 클릭되면 gameProcessedEventtrue 가 됩니다.이는 또한 ContextActionService를 통해 연결된 입력 이벤트에도 적용됩니다.


TouchTapInWorld

TouchTapInWorld 이벤트는 사용자가 TouchEnabled 장치의 화면에 손가락을 터치/탭하면 발생합니다.사용자가 게임 세계를 탭하면 발사됩니다.

이 이벤트를 사용하여 사용자가 화면을 탭하고 GuiObject 요소를 탭하지 않는 시기를 결정할 수 있습니다.사용자가 GUI 요소를 탭하면 UserInputService.TouchTap가 TouchTapInWorld 대신 발사됩니다.

사용자의 장치가 TouchEnabled인지 확인하고 터치 이벤트가 발생하는지 보려면 UserInputService.TouchEnabled를 참조하십시오.

이 이벤트는 Roblox 클라이언트 창이 포커스에 있을 때만 발생합니다. 예를 들어, 창이 최소화되면 입력이 캡처되지 않습니다.

로컬에서만 발사되므로 LocalScript 에서만 사용할 수 있습니다.

참조하세요:

매개 변수

position: Vector2

터치 위치를 나타내는 A Vector2

processedByUI: boolean

사용자가 GUI 요소를 탭했는지 여부.


WindowFocusReleased

The UserInputService 창 초점 해제 이벤트는 Roblox 클라이언트의 창이 초점을 잃을 때 발생합니다 - 일반적으로 Roblox 클라이언트가 사용자에 의해 최소화되면.

예를 들어, 아래 코드는 Roblox 클라이언트가 초점을 잃을 때마다 *“창 초점 해제”*를 출력합니다.


local UserInputService = game:GetService("UserInputService")
UserInputService.WindowFocusReleased:Connect(function()
print("Window focus released")
end)

이 이벤트는 Roblox 클라이언트가 사용자의 화면에 적극적으로 초점을 맞추고 있는지 여부를 추적하기 위해 UserInputService.WindowFocused와 함께 사용할 수 있습니다.

로컬에서만 발사되므로 LocalScript 에서만 사용할 수 있습니다.


WindowFocused

The UserInputService 창에 초점이 맞춰진 이벤트는 Roblox 클라이언트의 창이 초점을 얻을 때 발생합니다 - 일반적으로 Roblox 클라이언트가 최대화되거나 사용자 화면에서 활성으로 열려 있을 때입니다.

예를 들어, 아래 코드는 Roblox 클라이언트가 초점을 얻을 때마다 *“창에 초점 맞춤”*을 출력합니다.


local UserInputService = game:GetService("UserInputService")
UserInputService.WindowFocused:Connect(function()
print("Window focused")
end)

이 이벤트는 Roblox 클라이언트가 사용자의 화면에 적극적으로 초점을 맞추고 있는지 여부를 추적하기 위해 UserInputService.WindowFocusReleased와 함께 사용할 수 있습니다.

이 이벤트는 로컬에서만 발생하므로 LocalScript 에서만 사용할 수 있습니다.