I assume that you have a a need for something like my car GPS which has a system with a touch-screen on which a keyboard is displayed when 'Destination entry' has been selected. The letters and numerals can be disabled (greyed out). Only valid continuation characters are enabled.
So, if one had already typed HEAV, the only keys available are E, I and Y. If Y is pressed, the only available keys are 'space' and 'backspace'. and the word is displayed as HEAVY. If I is selected, the display is updated to 'HEAVISIDE', and again, only 'space' and 'backspace' are available. However, if 'E' is selected, letter keys D, N and S remain selectable.
Assuming this is the effect you are seeking, it seems to me that the entry shouldn't be directly into a %rs box, but instead, you need to use the %'rs option, and to sample the keypresses with ADD_KEYBOARD_MONITOR@, then if valid options are pressed, update the display with WINDOW_UPDATE@
Because you can't grey-out the keys on a physical keyboard, you can just ignore the inappropriate ones, or reward the user with a BEEP@ !
As to how you manage the dictionary, I haven't got a clue, but it is probably some sort of tree structure*. I did a Google search, and there seem to be multiple options. One page suggested the cellphone autocomplete algorithm, but I always have autocomplete turned off, as once I get to SHI , the phone won't let me finish SHIN or SHIP or even SHILOH, but gives me an unacceptable choice!
It's also probably clumsy in Fortran, and if ever I had to re-invent that particular wheel, my solution would be brute force rather than elegant. I think that I would have to remember the actual acceptable keypresses so that a 'backspace' would have the capacity to remove more than one character if a group had been inserted, as in ISIDE with just I. Then, a backspace would revert to HEAV, not HEAVISID.
There is also the benefit that the whole computer's processing power is available while the user is interacting with it, and some elaborate work on the dictionary can be done seemingly without delay. So the computer could search the dictionary even if it was simply an alphabetical list to decide what characters were acceptable at any time.
Eddie
*The sort of thing that computer scientists love. It's in the lecture course after the point that most engineers have already left.