A proper key library! IsKeyPressed etc

I just want a proper key library instead of IsControlPressed.
A simple way would just be

  IsKeyDown(KEY_F24)
```
Even cooler would be to have a "Custom Keybinds" under the main menu, Then you could do something like
```lua
Key = RegisterKey("The button that does stuff!",KEY_F24)
function Key.OnStateChange(State)
  print("New key state: ",State)
end

Citizen.CreateThread(function()
  while true do
    if Key.IsPressed then
      --Code
    end
    Citizen.Wait(0)
  end
end)
```
5 Likes

Support! It’s inconvenient that inputs aren’t guaranteed to be the same for everyone.

100% for it !

as ash said , it’s source of trouble when key arn’t the same everyone

This would be an amazing feature and help out my server greatly! I hope that we get those votes to continue on this feature…

I dont want this at all because I would have to rescript my entire server!!! Are you nuts!!! Maybe have it like an addon option for programming but I do not want this to change! I think FiveM did a great job and they do not need to change it at all!!!

I really hoping you’re not being serious…

Nah, he’s just joking…

lmao
This is great xD

Any news on a system like this? Binding scripts to controls is really annoying as the keys are not guaranteed to be the same for everyone, and there’s usually always conflict with a controller.

This feature still wouldn’t make the keys ‘the same for everyone’, which is impossible even (keyboard layouts are a thing, you see?). You should handle this properly instead, for instance using the input identifiers in game help messages.

… which is easy to fix with an additional if condition.

Also to mention there’s a bunch of keys you can’t use, such as most of the numpad keys, some of the F keys.

What else can you use to check if the input is just keyboard without using GetLastInputMethod( 0 )?

Please.

1 Like

Yes please k thanks :smile:

2 Likes

If you are speaking of checking the input with GetLastInputMethod(int) - this is not sufficient. If you check to make sure that the active input mode is keyboard and mouse via this method, it is not very accurate. If you hold down a controller button and a keyboard button at the same time it still registers as being the input mode of keyboard and mouse.

Though why would you use a keyboard AND a controller at the same time? Last time I checked most humans only have 2 hands if they’re lucky…

1 Like

Take an RP community for example. People that use a controller while running on foot, say they are chasing after a suspect, will want to order the suspect to stop. If they are running with the controller, they will most likely take their pinky finger and hold down the N key to order the suspect to stop. This is probably also the case with some other examples, though this is the only one I could come up with off the top of my head.

I have to agree that not having “raw” input states is very limiting. A simple fix for Windows clients is GetAsyncKeyState (or just tapping into the game’s actual input system, which is the better alternative, since GAKS isn’t exactly “fast”, especially when you can use DirectInput or similar methods). Unfortunately, since the FiveM client locks down all PInvoke calls (which sucks, but it is what it is), we can’t do this ourselves.

Using the game’s mapped keys is all well and good, until a server owner sets things up for a specific key layout, only to find that some Joe Schmoe decided to remap “move forward” to mouse scroll down, or some other crazy combination.

Also, we flat out don’t have the ability to map to certain keys by default; I, O, P, F11, F12, NumPad0/1/2/3/7/9/+/-/. etc

The following is my enum for making my life easier with at least the “default” key bindings, you’ll notice the large amount of missing keys (all of which may not actually map to what you expect them to)

    // NOTE: These keybinds are for QWERTY keyboards.
    // AZERTY keyboards will have them in the same place, but with different characters.
    // We are only using binds that "exist" for both.
    public enum ControlKey
    {
        PageUp = Control.ScriptedFlyZUp,
        PageDown = Control.ScriptedFlyZDown,
        // Home
        // End
        // Insert
        Delete = Control.PhoneOption,

        ArrowUp = Control.Phone,
        ArrowDown = Control.PhoneDown,
        ArrowLeft = Control.PhoneLeft,
        ArrowRight = Control.PhoneRight,

        MouseScrollUp = Control.SelectPrevWeapon,
        MouseScrollDown = Control.SelectNextWeapon,
        MouseLButton = Control.Attack,
        MouseRButton = Control.Aim,
        // MouseMButton
        // MouseXButton1
        // MouseXButton2

        Escape = Control.ReplayToggleTimeline,
        Grave = Control.EnterCheatCode,
        Tab = Control.SelectWeapon,
        CapsLock = Control.SpecialAbilityPC,
        LeftShift = Control.Sprint,
        LeftCtrl = Control.Duck,
        LeftAlt = Control.CharacterWheel,

        Enter = Control.SkipCutscene,
        Backspace = Control.PhoneCancel,

        Hyphen = Control.VehiclePrevRadioTrack,
        Equals = Control.VehicleNextRadioTrack,
        Comma = Control.VehiclePrevRadio,
        Period = Control.VehicleNextRadio,
        // OpenBracket
        // CloseBracket
        // Pipe/BackSlash
        // SemiColon
        // Apostrophe
        // ForwardSlash

        // RightShift
        // RightAlt
        // RightControl

        Space = Control.Jump,

        A = Control.MoveLeftOnly,
        B = Control.SpecialAbilitySecondary,
        C = Control.LookBehind,
        D = Control.MoveRightOnly,
        E = Control.Pickup,
        F = Control.Enter,
        G = Control.Detonate,
        H = Control.VehicleHeadlight,
        // I
        K = Control.ReplayShowhotkey,
        L = Control.CinematicSlowMo,
        M = Control.InteractionMenu,
        N = Control.PushToTalk,
        // O
        // P
        Q = Control.Cover,
        R = Control.Reload,
        S = Control.MoveDownOnly,
        T = Control.MpTextChatAll,
        U = Control.ReplayScreenshot,
        V = Control.NextCamera,
        W = Control.MoveUpOnly,
        X = Control.VehicleDuck,
        Y = Control.MpTextChatTeam,
        Z = Control.MultiplayerInfo,

        N1 = Control.SelectWeaponUnarmed,
        N2 = Control.SelectWeaponMelee,
        N3 = Control.SelectWeaponShotgun,
        N4 = Control.SelectWeaponHeavy,
        N5 = Control.SelectWeaponSpecial,
        N6 = Control.SelectWeaponHandgun,
        N7 = Control.SelectWeaponSmg,
        N8 = Control.SelectWeaponAutoRifle,
        N9 = Control.SelectWeaponSniper,
        // N0

        // NumPad0
        // NumPad1
        // NumPad2
        // NumPad3
        NumPad4 = Control.VehicleFlyRollLeftOnly,
        NumPad5 = Control.VehicleFlyPitchDownOnly,
        // NumPad7
        NumPad6 = Control.VehicleFlyRollRightOnly,
        NumPad8 = Control.VehicleFlyPitchUpOnly,
        // NumPad9
        // NumPadPlus
        // NumPadMinus
        // NumPadMul
        // NumPadDiv
        // NumPadPeriod

        F1 = Control.ReplayStartStopRecording,
        F2 = Control.ReplayStartStopRecordingSecondary,
        F3 = Control.SaveReplayClip,
        F5 = Control.SelectCharacterMichael,
        F6 = Control.SelectCharacterFranklin,
        F7 = Control.SelectCharacterTrevor,
        F8 = Control.SelectCharacterMultiplayer,
        F9 = Control.DropWeapon,
        F10 = Control.DropAmmo,
        // F11
        // F12
    }

… then don’t set things up assuming a specific layout.

Also, see this design intent document: