Jump to content

fill variable with last press key in input box


Recommended Posts

Hiya,

Probably an very stupid question.

I did an search of the forum, but I only got keylogger crap.

I don't want to capture key's from outside the window.

What I'd like is an variable filled with the last key typed in an input box.

Or better yet, to go to an function when something is typed in the input box.

I can read the entire text in the input box with GUICtrlRead($inputbox), but I'd like single characters to be filtered/replaced when they are typed.

_IsPressed is not an option because it captures every key pressed and not only the ones typed in the input box. (And I don't like DLL calls in simple scripts)

I thought about some GUIGetMsg() return, but that one doesn't (probably logical) return press key's.

Any thoughts?

Thanks in advance.

My active project(s): A-maze-ing generator (generates a maze)

My archived project(s): Pong3 (Multi-pinger)

Link to comment
Share on other sites

Not hard...

While 1
    GUICtrlSetData($inputbox, StringReplace(GUICtrlRead($inputbox), " ", "_"))
    Sleep(100)
WEnd

:)

Edit: In case that wasn't clear, it replaces all spaces with and underscore...

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Yeah I got that, but isn't there a way to capture an keystroke sent to an input before it's entered?

-> type character -> capture character & replace character -> send replaced character to input

That would be cool, but unrealistic to expect.

You solutions is doable as well. What I'm trying to avoid are all characters exept hexadecimal.

I found this: StringRegExpReplace($input,"[^:xdigit:]", "#")

$input is my given GUICtrlRead of the inputbox. "#" Is entered to give me an visual of replaced characters.

But somehow [^:xdigit:] is giving me trouble. '^' Is supposed to give me not xdigit matches. (Where xdigit is hexadecimal as an regular expression)

You would think this script will give me back "abc###":

$input = "abcxyz"
$replacement = StringRegExpReplace($input,"[^:xdigit:]", "#")
msgbox(0,"",$replacement)

But it gives: "###x##". :)

The help gives me:

Match a character in the given class of characters. Valid classes are: alpha (any alphabetic character), alnum (any alphanumeric character), lower (any lower-case letter), upper (any upper-case letter), digit (any decimal digit 0-9), xdigit (any hexadecimal digit, 0-9, A-F, a-f)

Any thoughts?

Thanks,

Tri

My active project(s): A-maze-ing generator (generates a maze)

My archived project(s): Pong3 (Multi-pinger)

Link to comment
Share on other sites

Hmm, checked another post on xdigit.

Seems that regular expression 'macro' isn't working well... If I replace [^:xdigit:] with [^0-9A-Fa-f] it does work...

Ok, sort of fixed. Anyone knows if this is working as designed? (Short for: Am I doing something wrong?)

My active project(s): A-maze-ing generator (generates a maze)

My archived project(s): Pong3 (Multi-pinger)

Link to comment
Share on other sites

Ok, sort of fixed. Anyone knows if this is working as designed? (Short for: Am I doing something wrong?)

Let's ask the one who needed it:

Hey, Triblade! Will you let Triblade know if that's working or not?

Thanks!

:)

P.S. Code a test and try it, then let us know.

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

As I said in my previous text: When I use [^:xdigit:] as a regular expression, it returns '###x##'

If I use [^0-9A-F-a-f] it returns 'abc###' (Which is the correct awnser)

According to the Function Reference of the StringRegExp command: (the StringRegExpReplace command I use doesn't contain the regular expressions in the help)

[^:class:] = Match any character not in the class.

Valid classes are: alpha (any alphabetic character), alnum (any alphanumeric character), lower (any lower-case letter), upper (any upper-case letter), digit (any decimal digit 0-9), xdigit (any hexadecimal digit, 0-9, A-F, a-f)

I'm interrested in the xdigit class because this should be short for "0-9A-Fa-f".

So the code that returns the 'wrong' "###x##" is:

$input = "abcxyz"
$replaced = StringRegExpReplace($input, "[^:xdigit:]", "#")
Msgbox(0, "", $replaced)
oÝ÷ Ø    ݶ¡×­«kzÛ«Ëa{kmßÚ®¢Ör«¨¶+ºÚ"µÍÌÍÚ[]H    ][ÝØXÞ^][ÝÂÌÍÜXÙYHÝ[ÔYÑ^XÙJ    ÌÍÚ[]    ][ÝÖ×NPKQKYI][ÝË   ][ÝÈÉ][ÝÊBÙØÞ
    ][ÝÉ][ÝË    ÌÍÜXÙY
B

So as I asked above, am I doing something wrong here or is this xdigit just not working?

My active project(s): A-maze-ing generator (generates a maze)

My archived project(s): Pong3 (Multi-pinger)

Link to comment
Share on other sites

Once I finish helping my girlfriend with her physics work I will give you some code that will be able to almost do what you want it to do. I can show you how to capture keystrokes using a dll call to user32.dll and check if its a hex value or not. however stopping it from going into an input box is going to be hard because the input box is built to react on events.

Dave

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------"I don't need to know everything, I just need to know where to find it when I need it"....EinsteinAnd in our case... That's the AutoIT helpfile ;) Please read before posting!!!

Link to comment
Share on other sites

Once I finish helping my girlfriend with her physics work I will give you some code that will be able to almost do what you want it to do.

Thanks.

Anyway my Regular Expression problem is over. I didn't expect another bracket around it. That was my mistake.

I had to use [[:^xdigit:]] instead of [:^xdigit:] because [:^xdigit:] is an macro for some characters. Around that should be brackets to let the program know it has an regular expression.

Now for my input capture... I await patiently :)

My active project(s): A-maze-ing generator (generates a maze)

My archived project(s): Pong3 (Multi-pinger)

Link to comment
Share on other sites

Sorry for the late reply, I spent 2hours digging the windows API to work out some dll calls but the method I was initally going to use (freezing user input until the key is verified) didn't exactly work and the code i have used before i didn't realise was for mouse input not keyboard :S

I'm glad you found a solution though lol

:)

Dave

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------"I don't need to know everything, I just need to know where to find it when I need it"....EinsteinAnd in our case... That's the AutoIT helpfile ;) Please read before posting!!!

Link to comment
Share on other sites

As I said in my previous text: ...

So as I asked above, am I doing something wrong here or is this xdigit just not working?

My bad... :)

When you asked if it was working, I read that as "test my script for me", and gave you a smart-ass response. Could have been worse. My dumb-ass responses are more embarrassing... :">

Back to the reply in post #2. Do you really need to intercept the keystrokes, or would a loop that constantly edits the contents of the control (using your fancy new RegExp that now works) be better? Here are the two combined:

While 1
    GUICtrlSetData($inputbox, StringRegExpReplace(GUICtrlRead($inputbox), "[[^:xdigit:]]", "#"))
    Sleep(100)
WEnd

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

It does work, but it ain't pretty.

When you run that you see the the character you typed for 0,25 second (or less) in the box. After that it dissapears because of the replace.

For esthetic values I think i'm gonna keep it at the replace command after an conversion button is pressed (some button in my prog).

Thanks for the help :)

My active project(s): A-maze-ing generator (generates a maze)

My archived project(s): Pong3 (Multi-pinger)

Link to comment
Share on other sites

It does work, but it ain't pretty.

When you run that you see the the character you typed for 0,25 second (or less) in the box. After that it dissapears because of the replace.

For esthetic values I think i'm gonna keep it at the replace command after an conversion button is pressed (some button in my prog).

Thanks for the help :D

Have you looked into using the $ES_PASSWORD style on the input box? If it's not your input box, you can at least test to see if you can add it with GuiCtrlSetStyle(). Some can be changed, some can't.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • Moderators

Might have a look at GUICtrlRecvMsg().

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Might have a look at GUICtrlRecvMsg().

What you used for Params to achieve this...?

Got a linky to where you find out exactly what messages to send/rcv for various controls?

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...