How do I make a gui button that responds to both mouseclicks and keypresses?

I am trying to make a button that can only be activated when a tool is equipped and that the button can be activated either by clicking on it or pressing a key but I’m stumped on a couple issues.
The code(Excerpt):

local function PressOrClick(ActionName, Inputstate, Inputobject1, Inputobject2)
	if ActionName == "Click" then
		UIS.InputBegan:Connect(function(Input,gameprocessed)
			if gameprocessed then return end
			print(Inputobject1)
			if Input.UserInputType == Inputobject1 then
				print("it's working 1")
			elseif Input.KeyCode == Inputobject2 then
				print("it's working 2")
			end
		end)
	end
end
Player.Backpack:WaitForChild("tool").Equipped:Connect(function()
	ToolMenu = function()
		ContextActionService:BindAction("Click", PressOrClick, false, Enum.UserInputType.MouseButton1,Enum.KeyCode.F)
	end
	ToolMenu()
end)

Player.Backpack:WaitForChild("tool").Unequipped:Connect(function()
	print("its not working")
	ToolMenu = function()
		ContextActionService:UnbindAction("Click", PressOrClick, false, Enum.UserInputType.MouseButton1,Enum.KeyCode.F)
	end
	ToolMenu()
end)

The “working 1” and “working 2” texts are not printing. What’s the issue here?

The way I typically achieve this is by simply calling the callback function that is connected to a button’s MouseButton1Click event/signal whenever a particular key/input is pressed/entered.

local Enumeration = Enum
local Game = game
local UserInputService = Game:GetService("UserInputService")
local Script = script
local TextButton = Script.Parent

local function OnTextButtonClicked()
	print("Hello world!")
end

local function OnInputBegan(InputObject, GameProcessed)
	if GameProcessed then return end
	if InputObject.KeyCode == Enumeration.KeyCode.Q then
		OnTextButtonClicked()
	end
end

TextButton.MouseButton1Click:Connect(OnTextButtonClicked)
UserInputService.InputBegan:Connect(OnInputBegan)

Hmm I have thought of that but is there no other way than using two separate functions? Is it not possible to find two avenues to using the same function?

Well, I would first see what the keycode actually is.

I would also remove the elseif statement.

Do you mind elaborating? First seeing what the keycode actually is?

Simply just print out InputObject.KeyCode and InputObject.UserInputType.

Maybe something like this will work for you:
ContextActionButtonBugHelp_.rbxl (37.9 KB)