#key detection

51 messages · Page 1 of 1 (latest)

true violet
#

how to detect current key pressed and previous key that was pressed

jaunty bronzeBOT
#

studio** You are now Level 3! **studio

left dirge
#

user input service

true violet
left dirge
#

gimme a minute

true violet
#

okay

obtuse ravine
#

if Input.KeyCode == Enum.Key.Code.F then

true violet
# obtuse ravine wdym

for example if a player pressed A then changed it to D
i want two variable to keep track of them
currentkey would be D and previous key would be A

obtuse ravine
left dirge
#

i got it

jaunty bronzeBOT
#

studio** You are now Level 10! **studio

left dirge
#

basically

true violet
left dirge
#

make a variable for the current key

#

then

#

make another variable

#

called like prevkey or something

#

set the prevkey

#

to the currentkey

#

before the currentkey gets set to the key you currently pressing

#

basically

#

previousKey = currentkey
currentkey = input.KeyCode

obtuse ravine
#

local d = false
local a = false

UserInputService.InputBegan:Connect(function(inp)
if inp.KeyCode == Enum.KeyCode.D then
d = true
elseif inp.KeyCode == Enum.KeyKode.A then
a = true
end
end)

UnserInputService.InputEnded:Connect(function(inp)
if inp.KeyCode == Enum.KeyCode.D then
d = false
elseif inp.KeyCode == Enum.KeyKode.A then
a = false
end
end)

jaunty bronzeBOT
#

studio** You are now Level 4! **studio

obtuse ravine
#

i dont really know what you mean but thats the script from what i understand

left dirge
#

he just needs the one before it

obtuse ravine
left dirge
left dirge
obtuse ravine
#

ahhh

#

I get it

#

so he probably wants to create somethin like ctrl + C right

#

anyway

true violet
#

or am i wrong

left dirge
#

no

#

because

#

its placed before it

#

so basically

#

if currentkey is nil

#

then previouskey will become nil but then the currentkey will change to a

#

or whatever u press

#

so then previouskey will become a but currentkey will become something else

#

cause code runs from top to bottom

#

not all at once

true violet
#

okay got it

#

thnakyou