Jump to content
Sign in to follow this  
LeCaillou

About sending keys

Recommended Posts

Hi everyone.

I made a script which doesn't work the way i would like to. I need it to send the enter key each time I type a letter. The enter key has to be sent only once, whether the key i manually press is kept down or not. I hope it's clear enough ^^

Here's the code i wrote so far :

#include <Misc.au3>

$var1=57
$var2=58
$var3=43
$var4=56
$var5=42

while 1
    If _IsPressed($var1) Then
        Send("{Enter}")
        ExitLoop
    EndIf
Wend

For now each time i press that key the enter key is sent every few ms... I know the while is the cause but i don't know how i could adapt the code to do what i explained above.

Thanks for reading and eventually answering me :)

Edited by LeCaillou

Share this post


Link to post
Share on other sites

use this instead:

while 1
    If _IsPressed($var1) Then
        While _IsPressed($var1)
            Sleep(10)
        WEnd
        Send("{Enter}")
        ExitLoop
    EndIf
    Sleep(10)
Wend

EDIT: I don't know what the rest of your code looks like, but I don't know if you want the "ExitLoop" to be there or not

Edited by danwilli

Share this post


Link to post
Share on other sites

I can't use your code because i need enter to be sent as soon as i press the key, not when i release it. More than that enter has to be sent only once, no matter how long i keep the key pressed. That's also why i tried exitloop in fact :)

EDIT : The whole code is there, i wrote down the keys code but im doing my tests with one only.

Edited by LeCaillou

Share this post


Link to post
Share on other sites

Mayb42

e...

#include <Misc.au3>

; for testing
Run("notepad.exe")
WinWaitActive("")

$var = StringSplit("57,58,43,56,42", ",")
$hold_key = ""

While 1
    For $x = 1 To $var[0]
        If $var[$x] <> $hold_key And _IsPressed($var[$x]) Then
            Send($var[$x] & "{Enter}")
            $hold_key = $var[$x]
            ExitLoop
        EndIf
        Sleep(1)
    Next
WEnd56

8)

Share this post


Link to post
Share on other sites

Oh it almost works :)

It also sends "57", "46" and other numbers while it sends enter (we can see that on your post too xD). I jsut need to tune it up i think. Can you still explain me the use of the for next here ? If i need to press the same key twice, to send twice enter after each of em your code doesn't work. Any way to fix that ?

Thanks anyway ^_^

Share this post


Link to post
Share on other sites

If you need enter on press rather than release, just change the order like I did below.

If you don't need the exitloop then I got rid of it.

while 1
    If _IsPressed($var1) Then
        Send("{Enter}")
        While _IsPressed($var1)
            Sleep(10)
        WEnd
    EndIf
    Sleep(10)
Wend

It looks like Valuater has a good script going that should do what you want, but if it doesn't work give mine a shot...

Start with Valuater's code though, as he is a guru :)

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  

×
×
  • Create New...