Jump to content

Write window title to txt file


Recommended Posts

Hello good people of AutoIT forum. bumblebee here, newbie (so help me God). :D

I would like to ask if it is possible to read a window title, trim the file name amd write whatever it reads to a file (a txt). For example this image attachment.

As you will notice, as I point an area (the baby's nose), there is certain mouse coordinate reading at the left corner of the Irfanview window. I was hoping to have a script which on a hotkey, will read only the x,y coordinate (332, 257) then write them to a txt file so I guess a trimming action is needed? How will the script look like then? Will it also be possible to do all that without irfanview, just autoit?

Thank you for reading a newbie's query.

bumblebee is a newbie...so help me God.

Link to comment
Share on other sites

  • Moderators

This will return an Array when you call it, so you must give it a variable name as the example shows. I made a GUI to test it and it comes back correct.

$show = _WinGetTitleAndCoord() ; Will return an array [1] = X and [2] = Y
If IsArray($show) Then
    MsgBox(0, 'info:', 'X: = ' & $show[1] & @CR & 'Y: = ' & $show[2])
EndIf


Func _WinGetTitleAndCoord($s_Start = 'XY:(', $s_End = ')')
    Local $aWinList = WinList(), $aStore = '', $iFound = 0
    For $iCount = 1 To $aWinList[0][0]
        If StringInStr($aWinList[$iCount][0], 'XY:(') Then
            $aStore = $aWinList[$iCount][0]
            $iFound = 1
            ExitLoop
        EndIf
    Next
    If $iFound Then
        $s_Start = StringInStr($aStore, $s_Start) + StringLen($s_Start)
        Return StringSplit(StringMid($aStore, $s_Start, StringInStr($aStore, $s_End) - $s_Start), ',')
    EndIf
    Return 0
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

If you just wanted the coordinates on the picture, couldn't you just use

MouseGetPos()

with

Opt("MouseCoordMode",2)

That returns the mouse position relative to the client area of the window, then

HotKeySet("^+w", "Write")

Func Write()
;Fuction to write to file
Endfunc

to make it so you push like Shift+Alt+w or something then it gets the current mouse position and writes it to your text file

Edited by Paulie
Link to comment
Share on other sites

  • Moderators

If you just wanted the coordinates on the picture, couldn't you just use

MouseGetPos()

with

That returns the mouse position relative to the client area of the window, then

HotKeySet("^+w", "Write")

Func Write()
;Fuction to write to file
Endfunc

to make it so you push like Shift+Alt+w or something then it gets the current mouse position and writes it to your text file

Ha!!

Well, yeah, I guess you could take the easy way out! :D

Edit:

I'm sure you meant Opt('MouseCoordMode', 2) rather than Opt('PixelCoordMode', 2) there by your definition.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Ha!!

Well, yeah, I guess you could take the easy way out! :D

Edit:

I'm sure you meant Opt('MouseCoordMode', 2) rather than Opt('PixelCoordMode', 2) there by your definition.

"PixelCoordMode" I never said that :D:evil: (I think i'm losing my mind)

personally nothigs wrong with the easy way :P;)

@thatsgreat

"MouseCoordmode" makes it relative to client area of the currently active window, so its not the whole screen, just like in bumbles screenshot

Link to comment
Share on other sites

Thanks to all who replied to my query. I think I have to re-read the help file as I'm going nuts not having this to work. Its alright I guess, I can always go back to this project at some other dates. :D

bumblebee is a newbie...so help me God.

Link to comment
Share on other sites

Thanks to all who replied to my query. I think I have to re-read the help file as I'm going nuts not having this to work. Its alright I guess, I can always go back to this project at some other dates. :D

Heres a sample of code that uses my method of just the relative window coordinates and it writes it to the file "PicCoords.html" which is created on Desktop

#include <file.au3>

Opt("MouseCoordMode",2)

Global $file, $once = 0
$PicDir=@DesktopDir
$PicFile='PicCoords.html'
DirCreate ($PicDir)

HotKeySet("!w","Write")

While 1
Sleep(400)
If $once < 1 then
     $file = FileOpen($PicDir&'\'&$PicFile, 1)
          If $file = -1 Then
              Exit
          EndIf
      filewrite($file,"<font face=Verdana size=1>")
    $once = 2
Endif
Wend

Func Write()
$window=wingettitle("")
$file = FileOpen($PicDir&'\'&$PicFile, 1)
     If $file = -1 then
          exit
     Endif
$pos=MouseGetPos()
FileWrite($file,"<font color=#008000 style=font-size:9px>" & $window & "</font><BR>" & @CRLF &"(" & $pos[0] & ", " & $pos[1]&")" & @CRLF &"<br><BR>")
FileClose($file)
Endfunc

I believe that should work OK

It is HARD trying to keep both autoit language and HTML languageg straight in you head :D

Edited by Paulie
Link to comment
Share on other sites

Hello Paulie. That was good stuff! I love the way it writes to HTML! Thanks for helping out. :D

So, HTML file created on desktop, coordinates plotted, however, the reading differs from that of IrfanView. By the way, Irfan view reads the coordinates at left mouse click and not by plain pointing. Sorry for the confusion on my initial post. The results:

Irfan = 135, 103

Paulie = 137, 132

Yes, I used the same point on the test graphic file. I love this forum. :D

bumblebee is a newbie...so help me God.

Link to comment
Share on other sites

  • Moderators

I'm curious with all the problems your having, if you even bothered to run the example I gave, I made a GUI window exactly like the one you showed in your pic and it returned an array.

$show[1] = X Coord and $show[2] = Y Coord, it will automatically find your window... To write the results to a file, you would simply do a

FileWriteLine("Your File", 'X = ' & $show[1] & @CRLF & 'Y = ' & $show[2])

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Hi SmOke_N,

I compiled your script as is (the first one) yesterday as sson as I read your reply then clicking the output EXE (I named it SmokeN), it just blinked. What to do? I'm trying to learn from the examples. Please don't get mad. I appreciate your willingness to help its just that I don't have an initial script yet so it would facilitate learning on my part if there is a sample script I can study.

The code you've posted, where will I place it? How will the script look like? Thanks.

Edited by bumblebee

bumblebee is a newbie...so help me God.

Link to comment
Share on other sites

  • Moderators

Hi SmOke_N,

I compiled your script as is (the first one) then clicking the output EXE (I named it SmokeN), it just blinked. What to do? I'm trying to learn from the examples. Please don't get offended. I appreciate your willingness to help its just that I don't have an initial script yet so it would facilitate learning on my part if there is a sample script I can study.

The code you've posted, where will I place it? How will the script look like? Thanks.

Do you have SciTe? Is the window open that your wanting to read? No need to compile if you have SciTe, Open the window, then once the window is open that has XY: in the title, you will then run the script (Alt+F5 from SciTe window), then you will get a message.

I am not offened, but more dissapointed I think, I looked through the AutoIt 123 tutorial posts of people that have used it in the past few days, and didn't see that you had tried it, if you do, you will understand a lot more tomorrow than you do today, and how to use Functions properly.

If you did not know about the tutorial, you can dowload it here.

And download SciTe Editor here (it's the first one 3.x mbs).

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Hello Paulie. That was good stuff! I love the way it writes to HTML! Thanks for helping out. :D

So, HTML file created on desktop, coordinates plotted, however, the reading differs from that of IrfanView. By the way, Irfan view reads the coordinates at left mouse click and not by plain pointing. Sorry for the confusion on my initial post. The results:

Irfan = 135, 103

Paulie = 137, 132

Yes, I used the same point on the test graphic file. I love this forum. :D

So, what your saying was that the Coords in mine and the one in your program dont match up?

If so, there is one thing to change that might help

Replace

Opt('MouseCoordMode',2)

With

Opt('MouseCoordMode',0)

That should help coord problem.

Also, was there any other way you wanted the file to display, now its

Windowname-

(X, Y)

Windowname-

(X, Y)

Just layout how to display it like I have above, and I can change it accordingly(or at least try)

Also, i didn't want to set the write hotkey to mousclick because i didn't know if that program you used had it just like when you move you mouse to coords changed, so i made it alt-w

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...