• Trending
  • Get Robux
  • How to create Game Pass?
  • Making Skins
  • Roblox Developers SALARY
  • CONTACT US
SUPPORT
Create your Roblox games to earn Robux with Roblox Studio :)
  • Home
  • Roblox Studio Tutorials
    Beginner TutorialsLua ScriptingRoblox CodesRoblox Studio Tips

    How to Handle Keyboard, Mouse, and Touch Input in Roblox Studio?

    BloxCreators
    BloxCreators
    September 24, 2025
    Beginner TutorialsEarn RobuxLua Scripting

    How I create the simple code redeem system in Roblox Studio?

    BloxCreators
    June 10, 2025
    Roblox lobby teleport
    Beginner TutorialsLua ScriptingRoblox Studio Tips

    How to create a Roblox Lobby system with teleport?

    BloxCreators
    July 15, 2025
  • LUA Scripting
    Beginner TutorialsLua Scripting

    How to make a simple Leaderboard with Roblox’s studio?

    Like almost every single game in Roblox has one. A roblox leaderboard…

    BloxCreators
    BloxCreators
    June 17, 2025
    Roblox lobby teleport
    Beginner TutorialsLua ScriptingRoblox Studio Tips
    How to create a Roblox Lobby system with teleport?
    Beginner TutorialsLua Scripting
    How to make a simple Leaderboard with Roblox’s studio?
    Beginner TutorialsLua Scripting
    How to Create an Interactive NPC Experience with Proximity Prompts?
    Beginner TutorialsLua Scripting
    How to make a Roblox Game Pass in 10 minutes?
  • Get Robux
    Beginner TutorialsLua ScriptingRoblox CodesRoblox Studio Tips

    How to Handle Keyboard, Mouse, and Touch Input in Roblox Studio?

    BloxCreators
    BloxCreators
    September 24, 2025
    Beginner TutorialsLua ScriptingRoblox CodesRoblox Studio Tips

    How to Handle Keyboard, Mouse, and Touch Input in Roblox Studio?

    BloxCreators
    September 24, 2025
    Beginner TutorialsRoblox Studio Tips

    21 Super Useful Hotkeys in Roblox Studio you must know

    BloxCreators
    May 14, 2022
  • Support Us
  • Bookmarks
Reading: How to Handle Keyboard, Mouse, and Touch Input in Roblox Studio?
Share
Create your Roblox games to earn Robux with Roblox Studio :)Create your Roblox games to earn Robux with Roblox Studio :)
Font ResizerAa
  • Adventure
Search
  • Home
    • Home 1
  • Categories
  • Bookmarks
    • My Bookmarks
  • More Foxiz
    • Blog Index
    • Sitemap
Have an existing account? Sign In
Follow US
© Foxiz News Network. Ruby Design Company. All Rights Reserved.
Create your Roblox games to earn Robux with Roblox Studio :) > Blog > Beginner Tutorials > How to Handle Keyboard, Mouse, and Touch Input in Roblox Studio?
Beginner TutorialsLua ScriptingRoblox CodesRoblox Studio Tips

How to Handle Keyboard, Mouse, and Touch Input in Roblox Studio?

Making Roblox game is not that difficult. One of the challenge is to handle different type of user input. Think about when you are playing Obby games or 99 nights in the forest, you need pressing a key to jump, clicking the mouse to fire a weapon, or tapping the screen on mobile.

BloxCreators
Last updated: September 24, 2025 6:53 pm
BloxCreators
Share
6 Min Read
keyboard, mouse, touched event
SHARE

Making Roblox game is not that difficult. One of the challenge is to handle different type of user input. Think about when you are playing Obby games or 99 nights in the forest, you need pressing a key to jump, clicking the mouse to fire a weapon, or tapping the screen on mobile. We simply call it listen and react to what players do. Being a Roblox game developer, I would like to share with you some tips on how to handle keyboard, mouse, and touch input in Roblox Studio today. By using simple examples, I will let you know how you can use different functions with variety of input parameters to make it work.

Contents
Getting Started: User Input in RobloxHandling Keyboard InputExample of Detecting Jump actionHandling Mouse InputExample of Detecting Mouse ClickHow to Detect Mouse Movement?Handling Touch Input (For Mobile)

Getting Started: User Input in Roblox

In Roblox engine, there is a special service called UserInputService to detect all kinds of player input. You can simply define a local variable as below:

local UserInputService = game:GetService("UserInputService")

Once you define the service, you can simply detect Keyboard presses (like W, A, S, D), you can detect Mouse actions (clicks, scrolls, movement) or you can even detect Touch gestures (taps, swipes on mobile)! To make it more interactive, you can connect events to this service to run different type of code when the player interacts.

Noted that you should create LocalScript under StarterPlayer -> StarterPlayerScripts

StarterPlayerScripts

UserInputService can only detect local player input (keyboard, mouse, or touch) on the client side.
If you create Scripts under ServerScriptService it won’t work. Why? Because those script run on the server, and it has no access to a player’s keyboard or mouse.

Handling Keyboard Input

Let’s start with keyboard input as an example. Noted that it’s just apply to player using computers, as mobile or iPAD do not use keyboard input at all.

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(input, isProcessed)
    if isProcessed then return end 
    if input.UserInputType == Enum.UserInputType.Keyboard then
        print("Key pressed:", input.KeyCode)
    end
end)

The code above initialize the UserInputService. And then waiting for the user input and print out the statement if any. Noted that the input.KeyCode tells you which key was pressed (e.g., Enum.KeyCode.Space). Also, the isProcessed is a boolean checking if Roblox already used the key (like typing in a chat box).

Let’s look at another example. This time we use the space for the jump action in Roblox. By default, space already reserved for jump action.

Example of Detecting Jump action

UserInputService.InputBegan:Connect(function(input, isProcessed)
    if not isProcessed and input.KeyCode == Enum.KeyCode.Space then
        print("Jump!")
        game.Players.LocalPlayer.Character:FindFirstChild("Humanoid").Jump = true
    end
end)

Handling Mouse Input

Other than keyboard, mouse input is detected in a similar way. However, instead of KeyCode, you use UserInputType.

Example of Detecting Mouse Click

UserInputService.InputBegan:Connect(function(input, isProcessed)
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
        print("Left Mouse Button Clicked!")
    elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
        print("Right Mouse Button Clicked!")
    end
end)

In this example, it detect if the user click the left click button of the mouse (MouseButton1) or right click button (MouseButton2). Once user clicked, Roblox studio print out the statement in the output window.

Output results

How to Detect Mouse Movement?

Easy! You can also track when the mouse moves easily by the following example:

UserInputService.InputChanged:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseMovement then
        print("Mouse Position:", input.Position)
    end
end)

When you move around with your mouse, you should see the results keep pop out in the output window

Mouse Position Detection

Handling Touch Input (For Mobile)

How about for those Mobile Users? Well, Roblox sends touch events as a type of UserInput. Let’s look at below example

UserInputService.TouchStarted:Connect(function(touch, isProcessed)
    print("Screen touched at:", touch.Position)
end)

UserInputService.TouchEnded:Connect(function(touch, isProcessed)
    print("Touch ended at:", touch.Position)
end)

When you add the script to the StarterPlayerScript, and once you touch the mobile screen, your position will be recorded and print out.

How to make a simple Leaderboard with Roblox’s studio?
Understanding If-Then-Else in Roblox Lua Scripting
Adding images in Roblox Studio: Roblox Decals
How to Create an Interactive NPC Experience with Proximity Prompts?
How to create a Roblox Lobby system with teleport?
TAGGED:KeyboardMouseRoblox studioRoblox User InputTouch Input
Share This Article
Facebook Email Print
Leave a Comment Leave a Comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

one × three =

New Releases

- Advertisement -
Ad image

Trending Stories

Beginner TutorialsLua Scripting

How to make a Roblox Game Pass in 10 minutes?

May 16, 2022
Roblox Game Publishing
Beginner TutorialsEarn RobuxLua Scripting

How to publish a game on Roblox?

June 3, 2025
Roblox lobby teleport
Beginner TutorialsLua ScriptingRoblox Studio Tips

How to create a Roblox Lobby system with teleport?

July 15, 2025
Beginner TutorialsEarn RobuxLua Scripting

How I create the simple code redeem system in Roblox Studio?

June 10, 2025
Beginner TutorialsMake Roblox Items

Adding images in Roblox Studio: Roblox Decals

May 14, 2022
Beginner TutorialsLua Scripting

How to Create an Interactive NPC Experience with Proximity Prompts?

June 5, 2025

Always Stay Up to Date

Subscribe to our newsletter to get our newest articles instantly!

Follow US on Social Media

Facebook Twitter Youtube

© Created and Maintained by the BloxCreators Team
All Rights Reserved 2025

Create your Roblox games to earn Robux with Roblox Studio :)

Contact Us

  • Job@BloxCreators.com
  • Privacy Policy
  • Advertise
  • Subscribe
Welcome Back!

Sign in to your account

Username or Email Address
Password

eighteen + thirteen =

Lost your password?