The DOS memory access is done by the dosmem functions and it's strongly recommended to use these functions.
Example:
function shift_state : byte; begin { $40:$17 contains the current contents of the shift, alt and strg keys} dosmemget($40,$17,shift_state,1); end;