I'm writing a text entry app that sits in the System Tray and assists in text entry via keyboard hooks. The current character the user types is determined by previous letters.
So if you have "I want to ben|" where "|" represents the caret, when the user hits the keyboard the next letter is determined by doing calculation on the previous letters of the word, "ben". It could either turn out to be 'd' > "bend" or 't' > "bent", etc.
This works fine if I'm starting each word from scratch, I can just keep track of the word in a String in my program.
The problem arises when I set the caret down in the middle of a word. I need to detect what characters come before the caret position. The situation also occurs if I press the arrow keys, etc.
In a past AutoHotkey app I did this by sending a "Shift + Ctrl + Left Arrow" command to highlight the characters, a "Ctrl + C" command to copy it, and then saved the clipboard into my String. I'm hoping that in a more robust language like C# I can avoid the ugly highlighting artifacts of this technique. Is there a way to get the characters programatically?
Note that this must occur in any text field across apps, so I can't get the characters from the text field itself (unless there's a way to access the currently in-focus text field).
What do you think?