[Help] - [C#] Show notification on VehicleHorn press

I have tried alot of different ways to do this, and I have no idea why my code is not working in-game. Tried different control presses and nothing works.

Edit: It doesn’t even need on VehicleHorn, I just want it to show something on a keypress.

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using CitizenFX.Core.UI;
using CitizenFX.Core;
using CitizenFX.Core.Native;

namespace Example
{
    public class Class1 : BaseScript
    {
        public Class1()
        {
            Tick += OnTick;
        }

        public async Task OnTick()
        {
            if (Game.IsControlJustPressed(0, Control.VehicleHorn))
            {
                Screen.ShowNotification("Vehicle horn was pressed!");
            }
            await BaseScript.Delay(0);
        }
    }
}

Can someone help me on this please? Thanks

Try with :

Game.IsControlJustPressed(1, Control.VehicleHorn)

and i’m not sure if namespace is required

IsControlJustPressed(int inputGroup, int control) you have to use an integrer.

Vehicle Horn is “86”

if (Game.IsControlJustPressed(1, 86))

Also do you have the function “ShowNotification”?

For example:

function ShowNotification(text)
	SetNotificationTextEntry("STRING")
	AddTextComponentString(text)
	DrawNotification(false, false)
end

This is the same 86 or Vehicule.Horn

Its not…

86 - Integrer
VehicleHorn - String

Citizen.CreateThread(function()
    while true do
	Citizen.Wait(0)
		if IsControlJustPressed(0, 86) then
			ShowNotification("Vehicle horn was pressed!")
		end
	end
end)

function ShowNotification(text)
	SetNotificationTextEntry("STRING")
	AddTextComponentString(text)
	DrawNotification(false, false)
end

It is in LUA but this way it is working for me.

your mistake is at the end of your task OnTick

you are using : await BaseScript.Delay(0); wich is only for make little delay of x milliseconde.

what you need to write is : await Task.FromResult(0);

and that should be working :wink:

no 0 is good , 0 is for keyboard and 1 for gamepad