The most likely problem is that you are trying to acces elements from dynamic array with no pre set lenght which means it has the lenght of 0 elements. In Delphi this would result in "Out of bonds" error but I'm not sure what error FPC would create.

Anywhay instead of trying to duplicate C++ method of imput hndling why don't you use one from Pascal based SDL demos.
It is not always good to directly translate source code from one programming language to another becouse not all programming languages alow using same aproaches.