Jump to content

I need help Function while <> keypressed

Recommended Posts

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


write the key, which was pressed to a file


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 :)

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")
  ElseIf _IsPressed('09') = 1 Then 
    $file = FileOpen("test.txt", 1)
    FileWriteLine($file, "TAB")


FileWriteLine($file, "Line1")


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

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

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.

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.


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.



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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...