Depending on your preference, you can get this feature using a (the easiest way) or by installing standalone mods for Forge or Fabric. Option 1: Use a Custom Client (Easiest)

: Supports version 1.18. Select 1.18 in the launcher, start the game, and press Right Shift to open the mod menu. Search for "Keystrokes" and toggle it on.

Custom clients come with Keystrokes pre-installed, so you don't have to manually download or move files.