How to enter scan codes

Many years ago I knew how to enter the scan code for a particular key in hex and generate a keystroke. I've completely forgotten how to do that. That was under DOS, but I'm assuming that such a function can be used under FreeBSD... The reason I ask is that I have a ThinkPad X220 which physically has a US keyboard but I've configured FreeBSD to use a UK keyboard and am unable to generate keys such as a pipe symbol. How would I go about creating characters that are not available on my keyboard? Or is there a dynamic way to alter 'keymap'?
I run DOS and you enter the ASCII number by hitting Alt-number. For example Alt-177. That's a pretty one. However, one caveat, you have to use the number pad because the scan codes are different for that than on the numbers up top. I'm particularly sensitive to that because I'm using a tenkeyless now.
If you only want to change your keybindings/layout for X, create a custom xkb mapping file (possibly including a standard/existing one and only add your own mappings) in ~/.xkb/symbols and compile/load it via xkbcomp and setxkbmap in your .profile.
I'm using this mechanism to get a modified programmers dvorak with german umlauts and some other modifications/additions. Here is what I added to my .profile:

setxkbmap -I /usr/home/sko/.xkb de-pdv -print | xkbcomp -I/usr/home/sko/.xkb - $DISPLAY
setxkbmap -model microsoft4000 -layout de-pdv
setxkbmap -option
setxkbmap -option caps:escape,shift:both_capslock_cancel,altwin:left_meta_win,lvl3:ralt

The crucial part are the first 2 lines, where the layout is first compiled and imported into the xkb-database by xkbcomp and then set by setxkbmap -layout

You could also just link the file into /usr/share/X11/xkb/symbols; this way it shold (?) be compiled at boot and can be directly used by setxkbmap -layout <yourlayout>