How to create a brand new keybinding including the options menu configuration for it:
In mainmenu.gui you must add a new option for the bind so that it will show up in the options menu. For this tutorial I will add a USE impulse key that can be used to interact with items other than shooting at it using the attack button.
To achieve this you have to do the following:
Load guis/mainmenu.gui and find an empty slot. As an exmaple I will add my new keybinding to the Attack/Look menu entry. There are three empty slots in there so we can use them for our own purpose.
The last entry there is sprint. Now go to the editor and search for //SPRINT. Scroll down a few lines and you will find a line //FILLER. This is the first slot that is empty.
To make it look as the others you must change the colorsettings from
matcolor 0, 0, 0, 0.2
to
matcolor 0, 0, 0, 1
Now scroll up again to the previous entry (SPRINT) and copy the lines beginning with windowDef CA10Title until the end of the second block that follows (bindDef CA10Primary) at the end of your filler definition. Dont forget to change the numbers CA10 to CA11 in our case. I don't know if it will create problems if you don't but I didn't test it and it makes it cleaner.
Now when you look at your CA11Title section you can find an entry 'text "#str_04066"' there. This string references a stringtable in strings/english.lang. With def files you can easily copy the file in your own mod directory, rename it and it is still loaded. This doesn't seem to be the case for this strings, so you should copy the entire file in your mod directory, where you, of course, created also a strings directory. Load this file into your editor and go to the end of it. Now add a new string with a new number like that '"#str_10000" "Use"'.
The last thing you have to do is to define the function that should be called when pressing that key. Go to the CA11Primary section and replace the bind command with your own function 'bind "_impulse41"'. impulse41 is not used.
When you fire up Doom3 now, you can open the options dialog look at ATTACK/LOOK and you should already see the new keybinding there and you can define which key should be bound to that function. Of course it will not do anything because we didn't write the code yet, but it is arelady saved to the DoomConfig.cfg file and will be persistant when you reload your mod.
Now we do the SDK code part.
Find the includefile usercmdgen.h and search for IMPULSE_40. You will note that there are several flagged a unused. Of course we can use this items, but I don't know for sure that ID has no plans for it so I will create this new one 41. Could well be that ID releases a patch with a new weapon or feature and then this might be used.
Add a new entry by copying IMPULSE_40 to IMPULSE_41 and don't forget to change the number as well. Now open player.cpp and look for idPlayer::PerformImpulse. You can add now a new switch case IMPULSE_41 at the end of the switch and do whatever you want in there. That's it. Your new keybinding is now working and you even have an entry in the options menu so that the player can select one of his own choice.
One useful hint I ran into: When you rename your function for some reason, you must reassign the key. Otherwise your new function will not be bound and the key refers to the old function. In my case I wanted to use tdm_frob and then used _impulse41 instead and my key was still bound to tdm_frob which didn't exist.