IPB

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> About how to run MMB code from AutoIt script, just an example of AutoIt/MMB communication (MMB 4.9.8 required)
odklizec
post Nov 2 2007, 01:43 PM
Post #1


MMBForums Ultra Elite
Group Icon

Group: Administrators
Posts: 7,417
Joined: 25-December 04
From: CzechoSlovakia
Member No.: 95



Hi folks,

For those of you who use AutoIt in your MMB projects, here is an example how to run the MMB code directly from AutoIt script!

With the below code you can not only run the MMB functions, but also create a MMB variables! So you can send the AutoIt variable directly to MMB and without hassling with clipboard or writing variables to file icon_wink.gif Hope you will find it useful.

CODE
#include <A3LMemory.au3>

Global Const $WM_RUNSCRIPTCODE = 0x08C7
Global Const $RUNSCRIPTCODE_LOUD = 1
Global Const $RUNSCRIPTCODE_QUIET = 0
Local $iItem, $pMemory, $tMemMap, $pText

; get handle of MMB window (just insert MMB title as a parameter)
$hwnd = WinGetHandle("Welcome!")

; autoit variable containing MMB function/variable, which you want to run from AutoIt
; for example Message box
$stringToSend='Message("","OK")'
; or AutoIt variable send to MMB variable
; $AutoItVar = "This is an AutoIt variable"
; $stringToSend="test$='" & $AutoItVar & "'"

;and this is an example of passing AutoIt variable to MMB variable
;$stringToSend="test$='OK'"

; get length of passed string
$slen = stringlen($stringToSend) +1

$str = "char[" & $slen & "]"; structure item must be "char"
$struct= DllStructCreate($str); create a struct for the string so we can get a pointer to it
if @error Then
    MsgBox(0,"","Error in DllStructCreate " & @error)
    exit
endif

$iItem   = DllStructGetSize($struct); get structure size
$pMemory = _Mem_CtrlInit($hwnd, $iItem, $tMemMap); init memory and return pointer to initialized memory in target app
DllStructSetData($struct, 1, $stringToSend); set string to structure
$pointer = DllStructGetPtr($struct,1); pointer to string in structure
_Mem_CtrlWrite($tMemMap, $pointer, $pMemory, $iItem); write string pointer to application memory
    
    
$result = DllCall("user32.dll","int","SendMessage","hWnd",$hwnd ,"int",$WM_RUNSCRIPTCODE,"int",$RUNSCRIPTCODE_LOUD,"ptr",$pMemory)
If @error Then
        MsgBox(0,"_ToggleMonitor", "_SendMessage Error: " & @error)
        Exit
    EndIf

_Mem_CtrlFree($tMemMap);release the memory

To be able to use this code, you need the latest AutoIt and Auto3Lib but it also requires some registry editing to make the Auto3Lib installable. At this point, I would like to thank the AutoIt forum member Zedna, who directed me on a correct way when I stuck with converting MMB SDK SendMesage call to AutoIt! icon_wink.gif

If you have any questions, don't hesitate to ask.


--------------------
Need Help? Don't hesitate to ask, but first..
1. Read Help file!
2. Examine Samples!
3. Search!
Now ask for help! ;)

I'm no longer a part of Mediachance team so all your questions regarding the Mediachance prices, payment options, lost serials and download links will be answered via the Mediachance contact form:
http://articles.mediachance.com/contact/
Go to the top of the page
 
+Quote Post
Shafayat
post Nov 3 2007, 11:58 AM
Post #2


MMBForums Elite
Group Icon

Group: Members
Posts: 1,262
Joined: 29-October 06
From: Flute Lake, Hamilton.
Member No.: 13,756



WOW icon_smile.gif

Thanks


--------------------


Go to the top of the page
 
+Quote Post
kkkmmb
post Nov 5 2007, 01:51 AM
Post #3


Registered User
Group Icon

Group: Members
Posts: 5
Joined: 13-July 06
Member No.: 12,056



GREAT WORK

thanx
Go to the top of the page
 
+Quote Post
odklizec
post Nov 5 2007, 10:41 AM
Post #4


MMBForums Ultra Elite
Group Icon

Group: Administrators
Posts: 7,417
Joined: 25-December 04
From: CzechoSlovakia
Member No.: 95



You are welcome guys!

Psst.. the AutoIt is not the only application, form which you can run the MMB code. Orol already fixed the problem with flash fscommand and he is now working on adding two-three small additions, which may look minor, but which will bring you some long time asked features and many new possibilities for your MMB projects! Is there anyone who want to send variables from HTML/JavaScript code loaded in Browser object? I'm sure, there are plenty of you out there... icon_wink.gif Stay tuned!


--------------------
Need Help? Don't hesitate to ask, but first..
1. Read Help file!
2. Examine Samples!
3. Search!
Now ask for help! ;)

I'm no longer a part of Mediachance team so all your questions regarding the Mediachance prices, payment options, lost serials and download links will be answered via the Mediachance contact form:
http://articles.mediachance.com/contact/
Go to the top of the page
 
+Quote Post
Shafayat
post Nov 5 2007, 12:10 PM
Post #5


MMBForums Elite
Group Icon

Group: Members
Posts: 1,262
Joined: 29-October 06
From: Flute Lake, Hamilton.
Member No.: 13,756



I'll be. I'm not moving from my browser. icon_smile.gif Oooohhh I wish I could. icon_wink.gif


--------------------


Go to the top of the page
 
+Quote Post
GHOST SKIKDA
post Sep 30 2008, 03:10 PM
Post #6


Registered User
Group Icon

Group: Members
Posts: 6
Joined: 5-May 08
From: الجزائر مدينة سكيكدة
Member No.: 18,460



Thanks suicide_anim.gif


--------------------


Go to the top of the page
 
+Quote Post
Yuraj
post Mar 7 2009, 06:37 PM
Post #7


MMBForums Junkie
Group Icon

Group: Members
Posts: 662
Joined: 28-July 06
From: Slovakia
Member No.: 12,181



The script what posted previously odklizec is no longer supported in newest versions of AutoIt (because now A3LMemory doesn't exist, and now it is embedded to autoit (it uses only autoits memory.au3 library), just renamed functions),
Example how to use the function:
CODE
#include <MMBLib.au3>

$title = 'Welcome!'; Title of MMB window
$script = 'Message("Test","")'; MMB Script
SendScriptMMB($title,$script)

I have packed this to library for autoit (better usability)
Library for autoit:
Attached File  MMBLib.rar ( 750bytes ) Number of downloads: 47


--------------------
Go to the top of the page
 
+Quote Post
Shafayat
post Mar 7 2009, 06:53 PM
Post #8


MMBForums Elite
Group Icon

Group: Members
Posts: 1,262
Joined: 29-October 06
From: Flute Lake, Hamilton.
Member No.: 13,756



Thanks.

Do you know how can we use autoit to read a value (of a variable, string especially) from MMB?

Regards
Shafayat


--------------------


Go to the top of the page
 
+Quote Post
Yuraj
post Mar 7 2009, 06:56 PM
Post #9


MMBForums Junkie
Group Icon

Group: Members
Posts: 662
Joined: 28-July 06
From: Slovakia
Member No.: 12,181



QUOTE (Shafayat @ Mar 7 2009, 06:53 PM) *
Thanks.

Do you know how can we use autoit to read a value (of a variable, string especially) from MMB?

Regards
Shafayat

Using command line parameters. Like I'm using in my example:
CODE
Run("autoit_controls_mmb.exe","Welcome!") // Welcome is the parameter what we pass to autoit script

Then you can get in autoit script parameter from cmd using $CmdLine array:
CODE
$title = $CmdLine[1]

// First entry in array $CmdLine[0] is count of cmd params.
Pity that AutoIt can't create DLLs icon_sad.gif


--------------------
Go to the top of the page
 
+Quote Post
Nevercom
post Mar 8 2009, 01:23 PM
Post #10


MMBForums Superuser
Group Icon

Group: Members
Posts: 168
Joined: 24-July 06
From: Shiraz, Iran
Member No.: 12,137



Hi,

Shafayat asked about how to read a value from MMB, and i want to ask how to read a value from AutoIt with MMB ?
Actually I don't know how to send this code to MMB:
Data$ = 'SomeText' <= SomeText is a AutoIt Variable
RunScript("GetData")

My AU3 Code is like this:
CODE
#NoTrayIcon
#Region;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Add_Constants=n
#EndRegion;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------

AutoIt Version: 3.2.12.1
Author: Nevercom

Script Function:
    This will copy the text under Mouse Position to the Clip Board and will
    run such a script in MMB:
    Data$ = 'Selected Text'; Selected text is value of $Data in AutoIt
    RunScript("GetData")

#ce ----------------------------------------------------------------------------

#include <MMBLib.au3>

if @Compiled AND $CmdLine[0] == 0 then
    MsgBox(16,"Error","Missing CMDLine parameters!")
    Exit
endif

if @Compiled then
    $title = $CmdLine[1]; Get window title from CMD
Else
;$title = "Welcome!"; only for debugging
endif
;$title = 'Welcome!'; Title of MMB window
;$script = 'Message("Test","")'; MMB Script
;SendScriptMMB($title,$script)
Func _GetText()
  
    Local $PrevClip = ClipGet()
    Local $MPos = MouseGetPos()
  
    MouseClick('left', $MPos[0], $MPos[1], 2, 0)
    Send('^c')
   ;ConsoleWrite(ClipGet() & @LF)
    $Data = ClipGet()
    
    $script = 'Data$ = ' & $Data
    SendScriptMMB($title,$script)
    $script = 'RunScript("GetData")'
    SendScriptMMB($title,$script)
    ClipPut($PrevClip)
  
EndFunc

while 1
    if $CmdLine[2] == 'GetText' Then; I will send parameters to AutoIt like this: MMBWindowTitle GetText
        _GetText()
    EndIf
    Sleep(100)
WEnd

What i want to achieve from this code is:
1. When a Key Combination is pressed, My MMB App will run AutoIt Script with this parameters: MMBWindowTitle GetText
2. when AutoIt Script is running, if second parameter is GetText, go to _GetText() Function
3. Select(Highlight) the word Under the mouse Position
4. Copy that word to the Clip Board [Send('^c')]
5. Get the data from clipboard and put it in $Data variable
6. Send a script like this to MMB:
Data$ = 'Contents Of $Data Variable'
RunScript("GetData")

but i don't know how to mix variables correctly to work well with both AutoIt and MMB
Can you help me about this ?

Cheers,
Nevercom


--------------------
Go to the top of the page
 
+Quote Post
Yuraj
post Mar 8 2009, 03:07 PM
Post #11


MMBForums Junkie
Group Icon

Group: Members
Posts: 662
Joined: 28-July 06
From: Slovakia
Member No.: 12,181



Hi,
If you want send string from autoit to MMB, try this:
CODE
$string = "This is string."
$script = "data$ = '" & $string & "'"
SendScriptMMB($title,$script)

And then you can in mmb handle data$ variable.

...and integer to mmb:
CODE
$integer = 10
$script = "data = " & $integer
SendScriptMMB($title,$script)


--------------------
Go to the top of the page
 
+Quote Post
x A x Company
post Mar 9 2009, 09:18 AM
Post #12


MMBForums Junkie
Group Icon

Group: Members
Posts: 594
Joined: 1-January 08
From: Mosul, Iraq (Yemn currently)
Member No.: 17,448



Good work Yuraj icon_smile.gif
I really need it.

Thanks
Abduljabbar


--------------------
Abduljabbar Faaiz Al_Kazzaz
My humble website: xax.do.am
I'll be out for some months.
Go to the top of the page
 
+Quote Post
Shafayat
post Mar 25 2009, 12:38 PM
Post #13


MMBForums Elite
Group Icon

Group: Members
Posts: 1,262
Joined: 29-October 06
From: Flute Lake, Hamilton.
Member No.: 13,756



Yuraj, I know (ofcourse icon_wink.gif ) about command line. I've been using MMB and autoit for years.

What I want is a "non-command line" way. Like autoit runs MMB code using Memory. I want the reverse. Do you get it?


--------------------


Go to the top of the page
 
+Quote Post
Yuraj
post Mar 26 2009, 01:21 PM
Post #14


MMBForums Junkie
Group Icon

Group: Members
Posts: 662
Joined: 28-July 06
From: Slovakia
Member No.: 12,181



QUOTE (Shafayat @ Mar 25 2009, 12:38 PM) *
Yuraj, I know (ofcourse icon_wink.gif ) about command line. I've been using MMB and autoit for years.

What I want is a "non-command line" way. Like autoit runs MMB code using Memory. I want the reverse. Do you get it?

I don't know but impossible for now because there's any plugin for mmb for memory manipulation (maybe?).
In AutoIt it's possible to manipulate with memory with some UDFs ...
Well it's more complicated way than command line (and what's wrong in it? icon_smile.gif ). You will need allocate memory via plugin but don't know how to send the pointer or address of alloc. memory to AutoIt probably via cmd params ...


--------------------
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

 



RSS Lo-Fi Version Time is now: 9th February 2010 - 07:20 AM