Hello All

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
Mrbrown
Newbie
Posts: 5
Joined: Tue Aug 14, 2007 12:44 am

Hello All

Post by Mrbrown » Tue Aug 14, 2007 1:45 am

Hello to all,

This is my first post on this forum and, first of all, i want to say thank to all, because in 1 day or reading this forum i'm already able to write some line of code without previous experience of programming, really useful.

Ok, let's go to my problem, and i ask sorry in advance for my bad english.
I want to realize a very complex tool for my backgammon club; This tool must be able to watch a match in online backgammon room, must identify the moves of the match, export to a file in a determined format, pass this file to a Backgammon Analysys software that can classify the skill (like expert, novice, ecc) of the observed players, and after this recognize the classified players a database.
This is a resume of my intention, just for make you all to know my pourpose.
I already started to write the line of codes for the first operation, of course i still haven't more knowledge of Macro Scheduler, but most of the issue i was be able to solve by myself, but i cannot be able to solve this 2 problem.

First Problem.
I need to use the image recognition on the screen for a pourpose,
this is the code. (comment are in italian, but the code is very simple)

Code: Select all

label>graphicrec
//Nella cartella c:\imgmacro dovranno andare i file immagine sui quali effettuare la
//comparazione.
//Prendo uno screenshot della situazioneattuale e lo salvo nella cartella img macro col nome
//actualscreen.bmp
GetScreenRes>Xres,Yres
wait>2
ScreenCapture>0,0,Xres,Yres,C:\imgmacro\screenactual.bmp
MessageModal>screenshot catturato, premere ok per iniziare la comparazione


FindImagePos>C:\imgmacro\compactive.bmp,C:\imgmacro\screenactual.bmp,10,1,Xcoord,Ycoord,matchfound



MessageModal>Ho effettuato la comparazione, e ho trovato le seguenti coordinate X %Xcoord% e Y %Ycoord%, ho trovato %matchfound% corrispondenze

First of all i get the screen resolution and store in Xres and Yres, after this i use the capturescreen with Xres and Yres for get a complete screenshot.
I use the findimagepos for compare a previous stored fragment of image and i expect to store the results on the array Xcoord, Ycoord and matchfound.
I set a MessageModal for show me the result, but the problem is that i have the value 1 on the array matchfound, so the compare process has gived a match, but i havent anything on the array Xcoord and Ycoord, so the message modal dialog show me directly %Xcoord% and %Ycoord% because this array has not be setted.
What's wrong?


Second Problem

I need to check if the screen res is 1600X1200, if isn't block the script (and this work good in my code); after this i need to get the full window name of a child windows of the backgammon software for move in a certain position, and after start all the getpixelcolor
control for identify the moves. I can see this window name on the tool Window Viewer of macro scheduler. The name of this window every change but some text of the name is stille the same; So i thinked to use the procedure FindWindowWithText for get the full name and after move whenever i want.
This is my code for this

Code: Select all

GetScreenRes>Xres,Yres
If>Xres=1600,control2,ResError
ENDIF

// setto il label di errore e il messaggio.
Label>ResError
Let>MSG_STAYONTOP=1
Let>MSG_CENTERED=1
//in futuro rimuovere questi messaggi.
MessageModal>La risoluzione dello schermo non è impostata a 1600x1200.  Questa automazione ha bisogno di una risoluzione 1600x1200 per funzionare.
// Chiudo le macro.
goto>endprocedure

// dopo aver controllato la res X, controllo la Y, un pò brutto come codice
Label>control2
if>Yres=1200,continue,ResError
ENDIF

Label>continue
//Avviso che il check della risoluzione è andato a buon fine.
//in futuro togliere questi messaggi.
MessageModal>Screen Resolution is OK (1600x1200).
//controllo se una finestra di gioco è aperta tramite il testo ricorrente "vs."
Let>WIN_USEHANDLE=0
//cerco una finestra che contenga il testo desiderato "vs.", se la trovo
//memorizzo il nome finestra in una variabile, altrimenti quella variabile conterrà
//il valore NOT FOUND
FindWindowWithText>vs.,1,NomeFinestra
If>NomeFinestra=NOT FOUND,windowerror,Muovifinestra

Label>windowerror
MessageModal>Non ho trovato una finestra di gioco BgRoom, pertanto non posso spostarla. Ricontrollare eventuali errori.
goto>endprocedure

Label>Muovifinestra
MessageModal>Ho trovato una possibile finestra di Gioco BgRoom, chiamata %NomeFinestra%, ora tento di spostarla nella posizione prestabilita.
MoveWindow>%NomeFinestra%,5,8


label>endprocedure
MessageModal>La procedura è stata completata, è possibile che sia stata completata con successo oppure un errore abbia rimandato a fine procedura. Segue Messaggio che Mostra i valori delle principali variabili della procedura, al fine di procedere ad un debugging.
Wait>1
MessageModal> Valore variabili risoluzione X è %Xres%, Y è %Yres%, Il nome finestra Bgroom Rilevata è %NomeFinestra%.
As i said, the check of the screen resolution work properly, but when i try to use the FindWindowWithText procedure, the procedure don't found anything (value stored in array NOT FOUND) and if i select to use the WIN HANDLES options i get a result, but is a number like 5449738 that i'm not be able to use.
Like i said before i can be able to see the window name that i need
(i remember, is a child of the Backgammon oline room software) with the Macro Scheduler Window viewer tree tool.

I did any mistake?


Thank you to all who want to reply to my message, i hope to know you all iin the near future.

Best Regards

Alex

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Aug 14, 2007 7:17 am

Problem 1: xCoord and yCoord are arrays. FindImagePos can return more than one match, so xCoord and yCoord contain each matching position. So the first matching position is in xCoord_0, uCoord_0 so you need:


MessageModal>Ho effettuato la comparazione, e ho trovato le seguenti coordinate X %Xcoord_0% e Y %Ycoord_0%, ho trovato %matchfound% corrispondenze


Problem 2: FindWindowWithText is used to identify text *within* a window, not the window title. If some of the title is known simply use a * in the standard window functions:

WaitWindowOpen>Notepad*
SetFocus>Notepad*

This would wait for and focus the first window it finds whose *title* *contains* the word "notepad" *anywhere* within it.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Mrbrown
Newbie
Posts: 5
Joined: Tue Aug 14, 2007 12:44 am

Post by Mrbrown » Tue Aug 14, 2007 4:36 pm

Thank really a lot for the support, issue solved and all work properly now.
Best Regards

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts