Patch:Scancodes

From KeenWiki
Jump to: navigation, search

Scan codes are values that represent keypresses in-game. They can be thought of as 'codes' that represent all the buttons a player can press. Each game in Keen Vorticons has a different set of codes, created by adding a value to the key's value. The same codes are used any time the game looks for a keypress, so if you know the code for a key you can use a hex editor to check where that key is looked for in the game executable.

In Keen Galaxy (And possibly Dreams) there are two other methods used. There is a table of 128 values in the executable which are either 0 or 1 depending on whether a key is being pressed. The game also keeps track of what key was last pressed. The first method the game used simply looks at what key has been pressed last. This is often used when several keys have the same effect (Such as returning to the Main Menu during gameplay) since this method allows the game to see if one of several keys have been pressed. When the game wants to check if a specific key is being pressed (especially when that key may be being held down while other keys are being pressed.) it calls this table and looks at a particular value. (Since the table is made of words the value it checks is the table start value plus the scancode * 2)

The values of keys are as follows:

ESC       $01   U           $16   | or \      $2B   F6          $40
! or 1    $02   I           $17   Z           $2C   F7          $41
@ or 2    $03   O           $18   X           $2D   F8          $42
# or 3    $04   P           $19   C           $2E   F9          $43
$ or 4    $05   { or [      $1A   V           $2F   F10         $44
% or 5    $06   } or ]      $1B   B           $30   NUMLOCK     $45
^ or 6    $07   ENTER       $1C   N           $31   SCROLL LOCK $46
& or 7    $08   CTRL        $1D   M           $32   HOME or 7   $47
* or 8    $09   A           $1E   < or ,      $33   UP or 8     $48
( or 9    $0A   S           $1F   > or .      $34   PGUP or 9   $49
) or 0    $0B   D           $20   ? or /      $35   NUMPAD -    $4A
_ or -    $0C   F           $21   RIGHT SHIFT $36   LEFT or 4   $4B
+ or =    $0D   G           $22   PRTSC/NUM*  $37   NUMPAD 5    $4C
BKSP      $0E   H           $23   ALT         $38   RIGHT or 6  $4D
TAB       $0F   J           $24   SPACEBAR    $39   NUMPAD +    $4E
Q         $10   K           $25   CAPSLOCK    $3A   END or 1    $4F
W         $11   L           $26   F1          $3B   DOWN or 2   $50
E         $12   : or ;      $27   F2          $3C   PGDN or 3   $51
R         $13   " or '      $28   F3          $3D   INS or 0    $52
T         $14   ~ or `      $29   F4          $3E   DEL or .    $53
Y         $15   LEFT SHIFT  $2A   F5          $3F 


The value added to this by each game in the Keen series is:

  1         $502C
  2         $5008
  3         $5258
  4         $C647
  5         $BCAF
  6         $C7D5
  D         $E48A


As an example the C T Space cheat code in Keen 1 is:

Patch: Keen 1
#CTSpace cheat keys:
%patch $11F5 $505AW %patch $11FC $5040W %patch $1203 $5065W


An example from Keen 5 is the help key (F1) and the F10 key used in cheats. The first one looks for the scancode, the second checks a place in the table. (Here the scancode for F10 is $44, since the table is in two-byte segments this becomes $88):

Patch: Keen 5
#Scancode for F1 help
%patch $78EA $3B
#Keen 5 F10 key
%patch $7A76 $BD73W
#$BD73 = $BCAF + $88


A simple way to disable something is to set one or more of its keys to $00. That is we use the value added by the game for at least one of the keys, a key that can never be pressed. (The code itself still works though, so can't be used by anything else.) Thus to disable the C T Space cheat we can use the patch:

Patch: Keen 1
#CTSpace cheat keys:
%patch $11F5 $502CW %patch $11FC $502CW %patch $1203 $502CW


To disable the help menu in Keen 5 use:

Patch: Keen 5
#Scancode for F1 help
%patch $78EA $00


See also