Sign in to follow this  
Followers 0
ChaosCookie

Getting the amount of letters when any Key _isPressed

8 posts in this topic

Hey all.. I got a pretty weird question and I hope that somebody can solve my Problem :o :

When you press a key and let it pressed for awhile, many letters are send depending on the time you are pressing the key...

You can easily record the time you pressed the key with TimerInit/Timerdiff but if you afterwards make a while-loop like this:..

$time = TimerInit()
$diff = 0

While $diff < 3000 ;just an example time
Send("Key")
$diff = TimerDiff($time)
Wend
;- Much more letters are send this way than just pressing a Key in those 3 seconds

...usually much more letters are send than with just manually pressing the key. So I tried different SendKeyDelay's but it seems that the number of letters send in the while-loop increase much more in a longer period of time than in the same time you manually press the key...

So what to do? I want the same amount of letters in the while-loop as I get when I manually press the key in an undefinded time..

Regards, ChaosCookie

(I hope my English is understandable :D)

Share this post


Link to post
Share on other sites



It appears to me your code is sending the key repeatedly for 3 seconds. In order to have it be at the same speed you can hit a key in three seconds, you have to figure out how many time you can press the key in 3 seconds, divide 3000 by the number of presses you can do and add a sleep for that number (3000/presses in 3 seconds)


Giggity

Share this post


Link to post
Share on other sites

Hey all.. I got a pretty weird question and I hope that somebody can solve my Problem :D :

When you press a key and let it pressed for awhile, many letters are send depending on the time you are pressing the key...

You can easily record the time you pressed the key with TimerInit/Timerdiff but if you afterwards make a while-loop like this:..

$time = TimerInit()
$diff = 0

While $diff < 3000;just an example time
Send("Key")
$diff = TimerDiff($time)
Wend
;- Much more letters are send this way than just pressing a Key in those 3 seconds

...usually much more letters are send than with just manually pressing the key. So I tried different SendKeyDelay's but it seems that the number of letters send in the while-loop increase much more in a longer period of time than in the same time you manually press the key...

So what to do? I want the same amount of letters in the while-loop as I get when I manually press the key in an undefinded time..

Regards, ChaosCookie

(I hope my English is understandable :o)

What's the point of this? If you need to know how many characters where sent, get the text from the edit/input control and parse it out. Why do you have to generate simulated keystrokes at the exact same rate as the native keyboard repeat?

: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

Share this post


Link to post
Share on other sites

Hey I just came home and tested your idea youknowwho4eva... Thank you very much! Thats how Im going to do this...But I got 2 little problems =/

1. 3000 was just an example... how to get the number of presses I can do in an unspecific time? xD

2. If you get to longer periods of time this method is getting a bit inexact (see my documentation below)

I tested your idea with the following script and documented it:

#include<Misc.au3>
$diff = 0
Opt("SendkeyDelay", INT(10000/306))

;========== if you want to press manually uncomment this: ==========
;~ While 1
;~ if _isPressed("41") Then ExitLoop
;~ WEnd
; ==================================================================

$time = TimerInit()

While $diff < 10000;just an example time
;===== comment this: ======
Send("a")
;==========================
$diff = TimerDiff($time)
Wend

;=== and uncomment this ===
;~ MsgBox(0,"","")
;==========================
;DOKUMENTATON:

;sleep-time = 1000/19:
;~ aaaaa aaaaa aaaaa aaaa => manually
;~ aaaaa aaaaa aaaaa aaa  => send/Opt (Opt is actually a tad more exact than just sleep)

;sleep-time = 3000/33:
;~ aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaa => manually
;~ aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aa  => send/Opt --> difference of 1 letter= cool!

;sleep-time = 5000/61:
;~ aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaaa a => manually
;~ aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaaaa aaa => send/Opt --> differnece of 4 letters= I can live with that!

;sleep-time = 10000/306:
;~ 306* a => manually
;~ 264* a => send/opt ---> difference of 42 letters =(

PS: ah and @Psalty this is going to be like an addon for a macrobot so I wont have anything to do with edits/inputs

Regards, ChaosCookie!

Share this post


Link to post
Share on other sites

instead of a while loop, what about a for loop, that will automatically press the key the number of times that manually you would do in the specified time?


Giggity

Share this post


Link to post
Share on other sites

hmmm but how to get the number of times the key is send while being pressed (manually) in an >undefined< time then? =p

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

$time = TimerInit()
$diff = 0

While
$div = $dif/50
if stringisdigit($div) = 1 then
Send("Key")
endif
$diff = TimerDiff($time)
Wend

You had that you could hit the key 19 times a second, this equates to 20 times a second. If it works the way I think it should. Add an elseif in there with an exitloop, or a hotkey to exitloop.

Edit: opps had it at 200 times a second

Edited by youknowwho4eva

Giggity

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I found another way... I can just check how many letters are send after the first letter in a specific time and then compare the periods of time I need to get a specific amount of letters... the problem is again that the periods arent proportional again so I cant make a rule out of it -.-

And I noticed that TimerInit jumps in 9ms steps instead of 1ms steps... is there any more precise way than TimerInit?

Here is the script I just made very fast to calculate which period of time I need to get any specific amount of letters:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <WinApi.au3>

Opt("GuiOnEventMode", 1)

GuiCreate("Time Calc", 220, 220)
$edit1 = GuiCtrlCreateedit("", 10,10)
$input = GuiCtrlCreateInput("Time", 60, 183,150)
$but = GuiCtrlCreateButton("Length", 10, 180)
GuiCtrlSetOnEvent($but, "len")
GuiSetState()

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

While 1
    sleep(100)
WEnd

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
Local $hWndFrom, $iIDFrom, $iCode, $hWndEdit
If Not IsHWnd($edit1) Then $hWndEdit = GUICtrlGetHandle($edit1)
$hWndFrom = $ilParam
$iIDFrom = _WinAPI_LoWord ($iwParam)
$iCode = _WinAPI_HiWord ($iwParam)
Switch $hWndFrom
    Case $edit1, $hWndEdit
        Switch $iCode
            Case $EN_CHANGE; Sent when the user has taken an action that may have altered text in an edit control
                $diff = 0
                If StringLen(GuiCtrlRead($edit1)) > 2 Then
                    $time = TimerInit()
                    while $diff < GuiCtrlRead($input)
                        $diff = Timerdiff($time)
                        sleep(1)
                    Wend
                    GuiCtrlSetData($input, $diff)
                    MsgBox(0,"",$diff)
                EndIf
        EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc;==>WM_COMMAND

Func len()
$a = StringLen(GuiCtrlRead($edit1))
MsgBox(0,"",$a)
EndFunc

Just write a time in the time input than focus the edit and just keep any key pressed until you get a msgbox... the number of letters in the edit field -2 are the letters send in your time...

Edited by ChaosCookie

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