• keypress hook problem
    3 replies, posted
hello everyone i want to make a key hook , there is my code hook.Add( "KeyPress", "keypress_use_hi", function( ply, key ) print(key) end ) the problem is when i press a key, it sometimes print twice,but i need this only run once, is there any way to slove it ? thank you very much
I'm not sure if this is because of prediction, but you can try doing a IsFirstTimePredicted check in there.
Or you could just check if the key is different to the previous one: [CODE] local oldkey hook.Add( "KeyPress", "keypress_use_hi", function( ply, key ) if key ~= oldkey then print( key ) end oldkey = key end ) [/CODE]
[QUOTE=code_gs;50871380]I'm not sure if this is because of prediction, but you can try doing a IsFirstTimePredicted check in there.[/QUOTE] thank you very much , it fix my problem!!! [editline]12th August 2016[/editline] [QUOTE=MPan1;50871383]Or you could just check if the key is different to the previous one: [CODE] local oldkey hook.Add( "KeyPress", "keypress_use_hi", function( ply, key ) if key ~= oldkey then print( key ) end oldkey = key end ) [/CODE][/QUOTE] this way will cause another problem, when i press a key it work,but i press the same key again, it won't work. use IsFirstTimePredicted can fix that, thank you any way
Sorry, you need to Log In to post a reply to this thread.