There are only a few circumstances where you would not promote to queen.
The first is if promoting to queen would cause stalemate. In that case, you would probably promote to bishop instead, because rook would cause the same problem as queen, and knight is harder to force mate with. In the rare case where a bishop would cause stalemate, you promote to rook instead.
The second is if promoting to knight would force checkmate faster or more surely than queen, which is so rare you practically need to play with the intent of making it happen.
Either one is trivial to determine in a chess-playing program.
Check 1: would a knight promotion cause immediate checkmate? If yes, then promote to knight.
Check 2: would a queen promotion cause immediate stalemate? If no, then promote to queen.
Check 3: would a rook promotion cause immediate stalemate? If no, then promote to rook.
Check 4: would a bishop promotion cause immediate stalemate? If no, then promote to bishop.
Check 5: would a knight promotion cause immediate stalemate? If no, then promote to knight.
Otherwise, promote to queen and take the stalemate.
Or you could simply make queen promotion the automatic default unless you advanced the pawn using a context menu to promote to a different piece.