Detecting mouse left click without hook?

Hey!

How can i check if Mouses right click is pressed?


input.IsMouseDown(MOUSE_RIGHT)

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”?

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:


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

Again, just use the KeyPress hook

But be aware, that will replace whatever hook is active in the gamemode for Think. Use something less threatening like this:


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)