Patch:Scancodes

From KeenWiki
Jump to navigation Jump to search

Scancodes 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:

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):

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:

Keen 1

#CTSpace cheat keys:
%patch $11F5 [$502CW]
%patch $11FC [$502CW]
%patch $1203 [$502CW]


To disable the help menu in Keen 5 use:

Keen 5

#Scancode for F1 help
%patch $78EA $00


Alternate methods in Keen Vorticons

In Keen Vorticons there is a third method possible; this relies on the standard ASCII codes and takes the keyboard input directly, without considering the layout. There are several limitations to this, for one thing certain 'control keys' such as ctrl and alt cannot be used. For another it is usually case insensitive; only lowercase letters being used. This method is used for most keyboard input in Vorticons, for example in the quit windows or Yorp messages. A full table of valid codes is given below:

nul $00
soh $01
stx $02
etx $03
eot $04
enq $05
ack $06
bel $07
backspace $08
tab $09
line feed $0A
vt $0B
np $0C
enter $0D
so $0E
si $0F
dle $10
dc1 $11
dc2 $12
dc3 $13
dc4 $14
nak $15
syn $16
etb $17
can $18
em $19
eof $1A
esc $1B
fs $1C
gs $1D
rs $1E
us $1F
' ' $20
'!' $21
'"' $22
'#' $23
'$' $24
'%' $25
'&' $26
"'" $27
'(' $28
')' $29
'*' $2A
'+' $2B
',' $2C
'-' $2D
'.' $2E
'/' $2F
'0' $30
'1' $31
'2' $32
'3' $33
'4' $34
'5' $35
'6' $36
'7' $37
'8' $38
'9' $39
':' $3A
';' $3B
'<' $3C
'=' $3D
'>' $3E
'?' $3F
'@' $40
'A' $41
'B' $42
'C' $43
'D' $44
'E' $45
'F' $46
'G' $47
'H' $48
'I' $49
'J' $4A
'K' $4B
'L' $4C
'M' $4D
'N' $4E
'O' $4F
'P' $50
'Q' $51
'R' $52
'S' $53
'T' $54
'U' $55
'V' $56
'W' $57
'X' $58
'Y' $59
'Z' $5A
'[' $5B
'\' $5C
']' $5D
'^' $5E
'_' $5F
'`' $60
'a' $61
'b' $62
'c' $63
'd' $64
'e' $65
'f' $66
'g' $67
'h' $68
'i' $69
'j' $6A
'k' $6B
'l' $6C
'm' $6D
'n' $6E
'o' $6F
'p' $70
'q' $71
'r' $72
's' $73
't' $74
'u' $75
'v' $76
'w' $77
'x' $78
'y' $79
'z' $7A
'{' $7B
' $7C
'}' $7D
'~' $7E
Del $7F

See also