Sign in to follow this  
Followers 0
BennyB

I need help Function while <> keypressed

7 posts in this topic

I'd like to write a script which logs my actions include the window title and the window text. My idea was:

start process

while (process is running) do

while (no key was hit)

compare windowtitle.old with windowtitle

if the title is different then

write the title and the window text to a file

else do nothing

wend

write the key, which was pressed to a file

wend

i can't find a function which is similar to "register if a key is pressed"

i'm not very good in english, I hope you understand me :)

Share this post


Link to post
Share on other sites



OK, I testet but one problem still having.

script shows like:

$pid = run("calc.exe","","")

$file = FileOpen("test.txt", 2)

While (ProcessExists($pid) <> 0)

  If _IsPressed('2A') = 1 Then FileWriteLine($file, "DRUCK");  

  If _IsPressed('0D') = 1 Then 
    $file = FileOpen("test.txt", 1)
    FileWriteLine($file, "ENTER")
    FileClose($file)
  ElseIf _IsPressed('09') = 1 Then 
    $file = FileOpen("test.txt", 1)
    FileWriteLine($file, "TAB")
    FileClose($file)
  EndIf

WEnd

FileWriteLine($file, "Line1")

FileClose($file)


Func _IsPressed($hexKey)
; $hexKey must be the value of one of the keys.
; _IsPressed will return 0 if the key is not pressed, 1 if it is.
 
 Local $aR
 $hexKey = '0x' & $hexKey
 $aR = DllCall("user32", "int", "GetAsyncKeyState", "int", $hexKey)
 If Not @error And BitAND($aR[0],0x8000) = 0x8000 Then Return 1
 Return 0
EndFunc;==>_IsPressed

If I press ENTER or TAB the script write nearly 18 times TAB to the file, is that normal, can I fix this problem?

Share this post


Link to post
Share on other sites

Looks like you could need a little Sleep in your while loop.

As it is now in your code it will as long as the key you are looking for is pressed it will write to the file so thats why you get so many of the same.

I am not sure what you are trying to do but I think you could get a better result from the HotKeySet () function.

Share this post


Link to post
Share on other sites

If I work with a sleep it can cause faults? isn't it?

I'd like to make a macro-recorder for installation routine.

Share this post


Link to post
Share on other sites

If I work with a sleep it can cause faults? isn't it?

I'd like to make a macro-recorder for installation routine.

<{POST_SNAPBACK}>

see http://www.autoitscript.com/forum/index.ph...opic=5760&st=40

partial quote from that post:

It also implements a keyup keydown state so slow typers don't feed in

IIII'''MMMM WRRITTINGGG SOMMEETHIINGGG... I was having problems with that last sleep(100) in the log func. I couldn't find a time that suited my fast typing and my slow typing without either skipping keys or adding too many to the log.

later


[size="1"][font="Arial"].[u].[/u][/font][/size]

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