Keyboard layout based on scancodes?

I would like to make a new keyboard layout that moves the modifier keys around. The problem is that this needs to be an xkb layout, because I still need to be able to switch to the Qwerty layout and the layout of my native language. Is there a way to write an xkb layout that works on the keycodes instead of the symbols?

That is, instead of this type of entry:

key <LCTL> { [ Control_L ] }; 

I would use this type of entry (doesn't work, just an example):

key keycode37 { [ Control_L ] }; 

I could then do something like put the Shift key where Alt was and move Alt to where the Windows key was:

key keycode133 { [ Alt_L ] }; 
key keycode64 { [ Shift_L ] }; 

If not, then could I write an additional symbols file and have X use that one when on the custom layout, and use the regular symbols file in the Qwerty and other layouts?

That would be more of a pain and less portable but I'm willing to try it if it's the only option. I've gone through the different layouts trying to understand just how the meta keys are defined and how to override them, but I can't figure it out. Also, I cannot find it documented anywhere. There exist tons of resources on making new keyboard layouts but nothing addresses the issue of moving the modifier keys around.

Thanks in advance for any help.

Here's a place to start
Scancode - Wikipedia, the free encyclopedia

Thanks, jgt. The only thing that I get from that is that the answer on how to perform this will be different for USB and PS/2 keyboards. Is that correct? If so, I have no problem limiting the technique to USB keyboards.