• Detecting mouse left click without hook?
    6 replies, posted
Hey! How can i check if Mouses right click is pressed?
[code]input.IsMouseDown(MOUSE_RIGHT)[/code]
[QUOTE=Coffeee;47997245][code]input.IsMouseDown(MOUSE_RIGHT)[/code][/QUOTE] And how would i check 1 time? When i do that command it returns true all the time and i need command when the key went down? Or someway that it runs 1 time.
Sounds like you want a hook. But your title says "without hook"?
[QUOTE=RealDope;47997308]Sounds like you want a hook. But your title says "without hook"?[/QUOTE] I am using think hook where i check for right click but it gets spammed there when i need only 1 time to call my function.
You're probably best off just using a hook that runs when a key is pressed, such as KeyPress and check if the button is IN_ATTACK2. But if you absolutely need to run this in Think, you could use a variable that changes when the button is initially pressed, and only does the very frame the button is pressed but this isn't changed yet: [CODE]local RMBClicked = false function GM:Think() if input.IsMouseDown(MOUSE_RIGHT) and RMBClicked == false then -- Code upon key pressed for the first frame RMBClicked = true end if input.IsMouseDown(MOUSE_RIGHT) == false and RMBClicked then -- Code upon release of the button RMBClicked = false end end[/CODE] Again, just use the KeyPress hook
[QUOTE=Zet0r;47997558]You're probably best off just using a hook that runs when a key is pressed, such as KeyPress and check if the button is IN_ATTACK2. But if you absolutely need to run this in Think, you could use a variable that changes when the button is initially pressed, and only does the very frame the button is pressed but this isn't changed yet: [CODE]local RMBClicked = false function GM:Think() if input.IsMouseDown(MOUSE_RIGHT) and RMBClicked == false then -- Code upon key pressed for the first frame RMBClicked = true end if input.IsMouseDown(MOUSE_RIGHT) == false and RMBClicked then -- Code upon release of the button RMBClicked = false end end[/CODE] Again, just use the KeyPress hook[/QUOTE] But be aware, that will replace whatever hook is active in the gamemode for Think. Use something less threatening like this: [CODE]local RMBClicked = false hook.Add("Think","DoMyRightClickThingy",function() if input.IsMouseDown(MOUSE_RIGHT) and RMBClicked == false then -- Code upon key pressed for the first frame RMBClicked = true end if input.IsMouseDown(MOUSE_RIGHT) == false and RMBClicked then -- Code upon release of the button RMBClicked = false end end)[/CODE]
Sorry, you need to Log In to post a reply to this thread.