Jump to content
Sign in to follow this  
HarryBeasant

Help to get a script to run on button click

Recommended Posts

HarryBeasant

Hello,

I would like this function;

Func _ReduceMemory($i_PID = -1)

If $i_PID <> -1 Then

Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID)

$ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])

DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0])

Else

$ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)

EndIf

Return $ai_Return[0]

EndFunc ;==>_ReduceMemory

to be ran when a button it pressed;

$Button_1 = GUICtrlCreateButton("Clean RAM", 105, 65, 120)

Please help?!

Share this post


Link to post
Share on other sites
HarryBeasant

Bump?

Share this post


Link to post
Share on other sites
Melba23

HarryBeasant,

Welcome to the AutoIt forum. :)

But please do not bump your posts within 24 hours. :mellow:

Remember this is not a 24/7 support forum - those who answer are only here because they like helping others and have some time to spare. You just have to wait until someone who knows something about your particular problem, and is willing to help, comes online. Be patient and someone will answer eventually - like this.

You will need to create a GUI to hold the $Button_1 control. Then you will either have to look for the event message sent by the button press within a GUIGetMsg loop or else use the OnEvent mode to intercept it directly.

If all that sounds like Chinese, then reading the Help file (at least the first few sections - Using AutoIt, Tutorials and the first couple of References) will help you enormously. You should also look at the excellent tutorials that you will find here and here - you will find other tutorials in the Wiki (the link is at the top of the page).

There are even video tutorials on http://www.youtube.com/results?search_qu...oit+tutorial&search_type=&aq=0 if you prefer watching to reading.

You know where we are if you get into difficulties. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
HarryBeasant

Thanks for the reply, i have this code at the top, i really can't figure these "case statements" it will really help if you could give me an example of a button when clicked running any command in code please

#include <GUIConstantsEx.au3>

#include <StaticConstants.au3>

$GUI = GUICreate("RAM Monitor", 321, 121, 270, 173)

$menumenu = GUICtrlCreateMenu("Menu")

$menuitem = GUICtrlCreateMenuItem("Help", $menumenu)

GUICtrlSetState(-1, $GUI_DEFBUTTON)

$Button_1 = GUICtrlCreateButton("Clean RAM", 105, 65, 120)

$Progress = GUICtrlCreateProgress(0, 1, 320, 27)

GUISetState(@SW_SHOW)

Share this post


Link to post
Share on other sites
Melba23

HarryBeasant,

You read those tutorials very quickly! :mellow:

Seriously, this is absolutely basic stuff - if you cannot get your controls to action than there is little point in coding. This example shows how to do it:

#include <GUIConstantsEx.au3>
$hGUI = GUICreate("Test", 200, 200)
$hButton = GUICtrlCreateButton("Test", 60, 80, 80, 30)
GUISetState()
While 1
Switch GUIGetMsg()
  Case $GUI_EVENT_CLOSE
   Exit
  Case $hButton
   MsgBox(0, "Pressed", "Test")
EndSwitch
WEnd

Now go and read those tutorials! :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
HarryBeasant

thanks! last question, that ram cleaning script, where abouts in that code you just wrote would it go?

Share this post


Link to post
Share on other sites
Melba23

HarryBeasant,

You can put it at the end like this: :mellow:

#include <GUIConstantsEx.au3>
$hGUI = GUICreate("Test", 200, 200)
$hButton = GUICtrlCreateButton("Test", 60, 80, 80, 30)
GUISetState()
While 1
Switch GUIGetMsg()
  Case $GUI_EVENT_CLOSE
   Exit
  Case $hButton
   _DoIt() ; Call the function here
EndSwitch
WEnd
Func _DoIt() ; Define the function here
MsgBox(0, "Pressed", "Test")
EndFunc

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
HarryBeasant

Bare with me here mate.

While 1
Switch GUIGetMsg()
  Case $GUI_EVENT_CLOSE
   Exit
  Case $Button_1
   _DoIt($Button_1) ; Call the function here
EndSwitch
WEnd
Func _DoIt(_ReduceMemory()
Func _ReduceMemory($i_PID = -1)
        If $i_PID <> -1 Then
                Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID)
                Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])
                DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0])
        Else
                Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
        EndIf
        Return $ai_Return[0]
EndFunc;==> _ReduceMemory()
While 1
        Sleep(100)
WEnd)
MsgBox(0, "Pressed", "Test")
EndFunc
Edited by HarryBeasant

Share this post


Link to post
Share on other sites
Melba23

HarryBeasant,

Close, but no cigar! :)

#include <GUIConstantsEx.au3>
$hGUI = GUICreate("Test", 200, 200)
$hButton = GUICtrlCreateButton("Test", 60, 80, 80, 30)
GUISetState()
While 1
Switch GUIGetMsg()
  Case $GUI_EVENT_CLOSE
   Exit
  Case $hButton
   _ReduceMemory() ; Call the function here
EndSwitch
WEnd
Func _ReduceMemory($i_PID = -1)
If $i_PID <> -1 Then
  Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID)
  $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])
  DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0])
Else
  $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
EndIf
Return $ai_Return[0]
EndFunc   ;==>_ReduceMemory

But I am not sure you should be playing with DllCalls if you cannot get them to run without so much help..... :mellow:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
HarryBeasant

thanks for all your awesome help!!!

Share this post


Link to post
Share on other sites
Melba23

HarryBeasant,

Here is a cleaned-up version of your script - take a good look and you will see where I have changed it and added comments to explain why:

#include <GUIConstantsEx.au3>
;
$GUI = GUICreate("RAM Monitor", 321, 121, 270, 173)
$menumenu = GUICtrlCreateMenu("Menu")
$menuitem = GUICtrlCreateMenuItem("Help", $menumenu)
$Button_1 = GUICtrlCreateButton("Clean RAM", 105, 65, 120)
$Progress = GUICtrlCreateProgress(0, 1, 320, 27)
GUICtrlCreateLabel("Current Memory Usage: ", 4, 32, 120, 20)
$Label1 = GUICtrlCreateLabel("", 124, 32, 200, 20) ; Create the label here so you can update it later
GUISetState(@SW_SHOW)
;
; Start a timer with a value to gurantee a quick response
$iBegin = 0
;
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $Button_1
   _ReduceMemory() ; Call the function here
EndSwitch
If TimerDiff($iBegin) > 5000 Then ; Do this every 5 secs - the intial 0 value means we do it as sson as we get here the first time
  $mem = MemGetStats()
  GUICtrlSetData($Progress, $mem[0] + 1) ; A trick to get Vista/Win7 progress bars to fill instantly
  GUICtrlSetData($Progress, $mem[0])
  ; Update the label - do not create a new one each time
  GUICtrlSetData($Label1, Round(($mem[1] / 100 * $mem[0]) / 1024) & " MB / " & Round($mem[1] / 1024, 0) & " MB " & " (" & $mem[0] & "% Load)")
  ; Reset the timer
  $iBegin = TimerInit()
EndIf
WEnd
;
Func _ReduceMemory($i_PID = -1)
SplashTextOn("RAM Cleaning", "In progress")
Sleep(1000) ; So you can see the splash screen
If $i_PID - 1 Then
  Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID)
  $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])
  DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0])
Else
  $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
EndIf
SplashOff()
Return $ai_Return[0]
EndFunc   ;==>_ReduceMemory

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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  

  • Similar Content

    • nooneclose
      By nooneclose
      Hello again, I am in phase two of my help bot. I cannot figure out how to properly code Autoit to click on a webpage button using the I.E UDF. I want to click on the button that I have attached as an image. This button does not have a name but it has an ID. Here is the HTML code for this button that I found using chromes developer inspector.
      HTML Code: 
      <img role="button" tabindex="-1" id="toolactions_INSERT-tbb_image" src="nav_icon_insertkey.gif" alt="New Work Order CTRL+ALT+I" draggable="false"> Here is the code that I have so far:
      ;******************************************************************************* ; Opens IE and fill out a New Workorder ;******************************************************************************* ; Start IE at the ** Tracking Application in ****** $oIE = _IECreate("https:I_am_Bound_by_my_company_to_not_reveal_this_webpage") ; Wait for a browser page load to complete _IELoadWait($oIE) Sleep(6000) ; Store the field names where the important data will be sent Local $nWorkOrderB = _IEGetObjById($oIE, "toolactions_INSERT-tbb_image") _IEAction($nWorkOrderB, "click")  I want my program to click on the button that looks like a piece of paper with a blue # 
      (For those wondering, I am allowed to send images just not the URL.) 
      As always any help would be appreciated. 

    • MJ36
      By MJ36

      How to click this button ? 
      I Try 
       
      func test () $oCorrectObj = "" $tags = $oIE.document.GetElementsByTagName("button") For $tag in $tags $class_value = $tag.GetAttribute("type") If string($class_value) = "buttont" Then $oCorrectObj = $tag MsgBox(0, "Level: ", "Level found :)") Else MsgBox(16, "Failed", "Not found.") ExitLoop EndIf Next If IsObj ( $oCorrectObj ) Then _IEAction ($oCorrectObj, "click") EndIF  
      and
       
      func klik () Local $oFound = "" Local $oBtns = _IETagNameGetCollection($oIE, "span") For $oBtn In $oBtns If String($oBtn.classname) = "yt-uix-button-content" Then $oFound = $oBtn EndIf Next _IEAction ($oFound, "click") EndFunc  
      Please Help 
      Can you click it by name?
    • faustf
      By faustf
      i guys , like title anyone  have idea if is possible , and if yes if  have example to post ?  i find in forum and in google but  i dont know   how can start  to create  button with icon over toolbar near  clock or is  goog before language layout .
      sorry i not post any script but i dont know  where to start
      thankz
      at  all
    • caramen
      By caramen
      Hmmm i am sorry  i had simular problem but i cant find back post. 
       
      How to hide a gui button ? 
       
      I Want to dodge the variable non déclaréd when i make button in
      if statment 
       
      thx before 
    • ademon
      By ademon
      Hi. I can open the editor with out problems but I can not compile because it is placed on another partition diferent from C.
      Can you provide an update of this bug?


×