Sign in to follow this  
Followers 0
nf67

Sending a random character?

2 posts in this topic

#1 ·  Posted (edited)

Hi there,

I am trying to write a script which sends random keystrokes instead of the actual pressed (lower- or uppercase) key.

However, I have not been able to find out how to get the key sent correctly, as the following didn't seem to work the way I intended it to:

Send(Chr(Random(97, 122, 1))) ;Lowercase character

Send(Chr(Random(65, 90, 1))) ;Uppercase character

Here's my script, if you comment out the hotkeysets for the random functions and enabling the YouPressed function instead it works fine though...:D

#Include <Misc.au3>

HotKeySet("{ESC}", "Quit")
HotKeySet("{NUMPADADD}", "BindKeys")

While 1
WEnd

Func BindKeys()
    For $BindUpper = 65 To 90
    HotKeySet(Chr($BindUpper), "RandomUpper")
    ;HotKeySet(Chr($BindUpper), "YouPressed")
    Next

    For $BindLower = 97 To 122
    HotKeySet(Chr($BindLower), "RandomLower")
    ;HotKeySet(Chr($BindLower), "YouPressed")
    Next

    While 1
        If _IsPressed("2D") = 1 Then
        UnbindKeys()
        EndIf
    WEnd
EndFunc

Func YouPressed()
    Local $Key = @HotKeyPressed
    MsgBox(0, "You pressed...", "The " & $Key & " key.")
EndFunc

Func RandomUpper()
    Send(Chr(Random(65, 90, 1)))
EndFunc

Func RandomLower()
    Send(Chr(Random(97, 122, 1)))
EndFunc

Func UnbindKeys()
    For $UnbindUpper = 65 To 90
    HotKeySet(Chr($UnbindUpper))
    Next

    For $UnbindLower = 97 To 122
    HotKeySet(Chr($UnbindLower))
    Next
EndFunc

Func Quit()
Exit
EndFunc

Thank you, and please remove if it's too KL related.

:D

note to self: sending the random triggers the function again sending another random which triggers it again which- etc.

Edited by nf67

Share this post


Link to post
Share on other sites



Anyone :D?

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