Help with keypressing

Hi. Im making addon that requires keypress detection but i have propblem when i press the key i have set up it just spams it. (I have set it up to say test in chat so it says test 3 times with 1 press) any better ways to do this?



if input.IsKeyDown(KEY_1) then
    net.Start("say")
    net.SendToServer()
end


Thanks!

i tried with that (propably did something wrong) nothign happend when i pressed the key

if input.WasKeyPressed(KEY_1) = true then

lua/autorun/client/cl_main_am.lua:34: ‘then’ expected near ‘=’



if input.WasKeyPressed(KEY_1) = true then		
     net.Start("say1")
     net.SendToServer()
end


well im little bit noob in lua still

try “==”
(It’s okay, I’m still a noob too.)
so if there’s any coding prodigy out there please don’t yell at me for trying to solve problems but end up being incorrect as well. :wink:

works like this


if ( input.WasKeyPressed(KEY_1) == true ) then 

but when i press it nothing happens

[editline]13th April 2016[/editline]

“This function only works in Move hooks, and will detect key presses even in main menu or when a typing in a text field.” Hmm… move hooks like GM:Move?

I think the problem is located where ever you are printing. I could be wrong, but if it worked with IsKeyDown but printed it 3 times, instead of once, it seems logical that the peoblem would be located there.

Edit: I can’t seem to figure it out, so I’m gonna leave it to the upper hand. Goos luck figuring it out!

well code in server side is



net.Receive("say1", function(len, ply)

ply:Say("Test", false)

end)


[editline]13th April 2016[/editline]

i dont think that is the propblem i think it could more be the hook (Think)

It issue is the hook you’re calling it within, because you’re holding the key down for more than 1 tick, which is in most cases ~15ms.

Use a hook like this

GM:PlayerButtonDown to send the message

Also you didn’t need the == true check, without any condition it’ll just check if it’s not nil or false

How can i use KEY_1 in GM:PlayerButtonDown

[editline]13th April 2016[/editline]

Wait found it nothing

[editline]13th April 2016[/editline]

Thanks to everyone for their help! :slight_smile: