This is a very good question indeed but it took me a long time to understand what you wanted.
So you are programming an interface and you wonder how the computer can tell if a player wants to play Kg1
or 0-0
taking short castle as an example. The answer is that if both moves are legal then none of them takes precedence and the player can play whichever they desire. You then need a device how the player can make their intention clear to the computer. For instance dragging their king outside the board could do the castling.
As BlindKungFuMaster explains in standard chess you do not have to worry about it since the King has to be on e1
for a castle to be a legal move. Then there is no other legal move that could take the King on g1
thus there is no ambiguity.
In Fisher Chess (chess 960) however you can have an initial position with the King on f1
and a Rook on h1
. In this case both Kf1-g1
and 0-0
would be legal moves. Even for over the board play the Laws (Appendix F) recommend a special procedure for castling to avoid misunderstanding.