Mouse.Keydown for shift doesn't work when Shiftlock is enabled?

So this just happened a few hours ago and I’m using Shift for sprinting in most my games, it was working fine before until a lot of old scripts on my games for sprinting stopped working when using Shiftlock, I know Keydown was deprecated but this used to work perfectly fine until today. I’m pretty sure this is a bug on roblox’s end.

3 Likes

That’s why you should use UserInputService instead.

Here is an example of how you can do it using InputBegan and InputEnded:

local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(iobj, gp)
    if gp then
        return --exit if the event has been processed by the game (i.e. textbox typing)
    end
    if iobj.KeyCode == Enum.KeyCode.LeftShift then
        plr.Character.Humanoid.WalkSpeed = 25
    end
end)
UIS.InputEnded:Connect(function(iobj, gp)
    if gp then
        return
    end
    if iobj.KeyCode == Enum.KeyCode.LeftShift then
        plr.Character.Humanoid.WalkSpeed = 16
    end
end)
3 Likes

I know I should be using UserInputService but this bug had broke a lot of my scripts in bunch of games and I don’t want to go through every single one of them to change it.

Well then what exactly do you want? Even if somebody posted a workaround which would fix your Mouse.KeyDown, you would still have to change the code everywhere, wouldn’t you?
It seems like you have no other choice :stuck_out_tongue:

That’s why I posted this as a bug so I thought Roblox would fix it I may not be the only one who’s having this problem

This is the struggles of being a developer. You need to update your practices so your game isn’t outdated and your players are not upset. But on the other hand, I feel you man :sleepy:

Ah, well in this category you ask for help with scripting, not report bugs.
Also, once a function/event/property is deprecated, roblox will no longer update it, ever. That means they won’t fix any bugs with it either.

Well I guess I’m going to have to do that to like 100+ scripts :disappointed_relieved:

Maybe you could utilize packages across your games instead, read here.

1 Like

Nevermind looks like this is not a solution not even UIS.InputBegan can detect when a player presses shift when Shiftlock is enabled.

It’s probably because ShiftLock triggers the gp boolean in the event. You can make your handler ignore it, but that means your WalkSpeed will change if you i.e. type in chat and hold shift.

Alternatively you can set EnableMouseLockOption to false under StarterPlayer to disable shiftlock.

Why did Shiftlock start triggering it now? This used to work fine before and I think this is a bug big games like Swordburst 2’s sprinting also broke when you have shiftlock enabled.

No idea. I guess it’s another bug roblox has to fix themselves

(one of many…)

Yeah, this is definitely why you should use UserInputService. Shift lock has priority and sets GameProcessedEvent to true as the input is observed by a CoreScript. KeyDown automatically sinks input if an internal system reserves that functionality (GameProcessedEvent as true).

I seem to have no issues regarding the use of UserInputService. As for KeyDown, I can’t say much because I stopped using that years ago and refuse to touch it again except as necessary for repros or converting legacy material over to new API.

Code repro (LocalScript in StarterPlayerScripts):

local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")

local LocalPlayer = Players.LocalPlayer
local PlayerMouse = LocalPlayer:GetMouse()

UserInputService.InputBegan:Connect(function (InputObject, GameProcessedEvent)
	if InputObject.KeyCode == Enum.KeyCode.LeftShift then
		print("LeftShift from UserInputService, GameProcessedEvent:", GameProcessedEvent)
	end
end)

PlayerMouse.KeyDown:Connect(function (Key)
	-- Wish I could just stick a nice Enum.KeyCode.LeftShift.Value here
	if Key:byte() == 48 then
		print("LeftShift from KeyDown")
	end
end)

Results:

Input Method Shift Lock Enabled Result
UserInputService No Print, GameProcessedEvent false
KeyDown No Print
UserInputService Yes Print, GameProcessedEvent true
KeyDown Yes Nothing

Alternatively, you can use ContextActionService, specifically BindActionAtPriority. Shift lock uses ContextActionService and creates a binding with the priority value of 2000, with core security. I believe you can override that with a higher priority or have it run in parallel when Left Shift is used.


Useful action bindings tab in your Developer Console.

Let that be a lesson on why you shouldn’t use deprecated objects, or change out from them at your earliest convenience. It’s worth the pain and suffering to get your code to work over agonising about changing many scripts and letting this be an impediment to progress.

3 Likes