I feel like you shouldn’t have to use the net library, since GM:KeyPress and GM:KeyRelease are available on both the client and server-side… unless you’re trying to send client-side variables to the server when F is pressed, then yes you would use the net library.
KeyPress and KeyRelease only let you detect IN_ENUMS ( as in keys like ATTACK and RELOAD ) - not a specific key - these may change depending on the bind the player has for that event. Plus it limits the amount of binds that can be used.
I’m looking for a way to detect when a KEY_ Enums is pressed and handle it server-side.
Then yes, using IsKeyDown will require you to send variables to the server-side using net.Start (which you send with net.SendToServer). On the server-side, you should then have a net.Receive (same name as net.Start), which will receive anything sent in the order it was sent. Be sure to add the network string to the server, or it wont work.
I think you have mis-understood my question. I know how to use the net library, and I know how to use IsKeyDown - using the KeyPress hook **is not ** an option as it only lets to detect key binds like ATTACK, ATTACK2, RELOAD, SPRINT, JUMP etc. so my only option it seems is to use input.IsKeyDown and send it to the server-side.
My question is how to do this efficiently, as if I detected that in a THINK hook or while loop, it would send every tick, and I can’t check if the key is released to allow it to send again as there’s no input.IsKeyReleased.
One question: is there a good reason why you don’t want to use binds? It’s important to remember that not everyone uses the same keyboard layout, most prominently international players, and so hard-coding a certain action to a specific key is in most cases a bad idea. If there’s a relevant bind that you could use instead (flashlight?), I think you should use that.
But if you really do HAVE to have F be the key, then it sounds like PlayerButtonDown/Up are the hooks for you
That is a good point, however I need more binds then is possible. There’s only USE, FLASHLIGHT, ATTACK, ATTACK2, RELOAD possible SCORE, plus there’s no logical positioning usually. I’ll make a way for the player to rebind possible.
use a bool, set it to false before running the tick hook, then set it to true and send the message, make a timer.simple in the tick that resets the bool to false every X seconds so it can be pressed again.