Sign in to follow this  
Followers 0
qwert

How to get individual keystrokes?

8 posts in this topic

I use a data entry field -- defined with GUICtrlCreateInput -- for the user to enter a document request "ID".

The problem is that I would like to examine each character, one at a time, as they are typed in. I guess the best analogy is to a word processor with type ahead -- or automated spell check/correction. I only need this to occur when the user is typing into that particular field (i.e., not into any one of the dozen other fields on the form).

Is there a way to "camp on" that particular input field and receive the individual characters? By the way, the script already handles input from a variety of other defined buttons using a While 1 ... EndW loop.

Thanks for any help.

Share this post


Link to post
Share on other sites



While 1
Tooltip(GuiCtrlRead($Input),0,0)
WEnd
Thanks for your response, but I'm afraid I don't understand. When I said "examine", I meant to be able to test each "next keystroke" with something like If $nextChar = "$" Then ....

And are you suggesting I can have more than one While 1 ... WEnd loop active within a script?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

A day's searching has led me to conclude that there are only three ways to receive keyboard input:

1. Defined HotKeys -- apparently the most direct method (you get every defined key that is pressed). I'll consider this as a last resort because of the complexity of defining about 50 keys that could occur in the input string.

2. _IsPressed method -- basically a polling of the keyboard. This would seem to be prone to timing problems, since each potential key would be have to be polled on each cycle.

3. Entry into a control defined with GUICtrlCreateInput -- the easiest to set up, but difficult (impossible?) to fashion a way to receive individual characters (which is what I was asking about in my first post).

Is there any other method? As I explained in the original post, I just need to receive individual keys as each is pressed -- and then formulate the proper result to display for the user while they're typing. I suppose some type of direct dllCall could be fashioned (if it could receive only keyboard input, not mouse clicks), but it's beyond my capabilities to know how to approach that.

Any suggestion of a good approach will be appreciated.

Edited by qwert

Share this post


Link to post
Share on other sites

Take a look at the script "Andreas Answers" in my sig, it replaces all new entered characters in the inputbox to something else, it's actually uses the same method as Paulie suggested but it will give an example how to do things :D


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

it will give an example how to do things

Thanks for your response.

I think you're suggesting that I just read the input control contents on each cycle of my While 1 ... WEnd loop and compare to the previous contents. Any difference means there's been another character typed in. Was there something else that I missed?

Share this post


Link to post
Share on other sites

Thanks for your response.

I think you're suggesting that I just read the input control contents on each cycle of my While 1 ... WEnd loop and compare to the previous contents. Any difference means there's been another character typed in. Was there something else that I missed?

Nope that's the basic idea.

Very simple to implement and as long as you have a short sleep in the loop the user won't notice a thing :D


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

Nope that's the basic idea.

Very simple to implement and as long as you have a short sleep in the loop the user won't notice a thing :D

Well, I guess that's the method I'll use. I do believe it will work fine for my current application. But for future uses, I'd really like to find a method that can directly vector keystrokes into the active script -- if there is such a method.

Thanks again.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0