Hello everyone,
I am working on a project, which corrects user input (reads input stream from keyboard with keyboard module hook) based on some rules.
I am trying to find the fastest way to delete and write the corrected word, after a user enters a wrong one.
Currently I am using pynput, but I noticed that it faces problem when the user types very fast.
To give you a better idea of what I am looking for, I quote the above pseudocode.

user enters a word
some_checks_are_made
if (ok):
  do nothing
else:
  press_the_backspace_button_until_delete_of_wrong_entered_word
  write_the_new_word

To make it even more clear, the main problem I am facing is that my program delays on deleting and writing the correct word and the user overlays the words written from the program.
e.g. (just an example - not program's functionality)

user writes 'honeu' (the correct word is honey)
program starts deleting and deletes until 'ho___'
user starts typing next word 'hello'
the result is 'hohelloney'
I tried explaining it as better as I could.

I am just asking for any suggestion or solution to this problem.
! They proposed me to do the above grab the word as it's being typed, calculate your correction, then go back to the text and make the correction all at once if the word is still there. This means storing the text in a buffer (not repeatedly simulating backspace presses).
But I don't know how to go back to the exact position that the word was written.
Thanks in advance.

My very first thought is that what you want to do is extremely annoying: You're grabbing the keystream away from the user right while the user is still typing. That's why word processors typically don't do that; they simply mark the (probable) error and let the user do the correction later. I have a "kitchen timer" app that pops up a modal dialog when it goes off, but that dialog accepts keystrokes to set a "pause" time. If I'm typing when it pops up, it steals my input which is extremely annoying twice: Not only does it maybe get set to some pause value and restarted, but the email (or Daniweb comment) that I'm typing into gets whatever is left. Bleaugh.

The other model to think about is how texting apps work: As you type, it displays the word(s) you are probably working on and lets you choose or take the default with a specific keystroke or gesture. This too doesn't back up: It just jumps forward in a manner dependent on the user's actions.

Can you rethink what your intention is?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.