PowNoob Posted August 28, 2010 Share Posted August 28, 2010 below is the code i got from this site and modified to my need. I'm using pixelsearch to search at location x825;y542 on my screen for color 0x7b6b4a; once located send "Enter" key. The problem is that, it's not working correctly, it will keep sending "Enter" key even when the color i'm looking for hasn't load yet.Scenario;I have two program I use and it get disconnected all the time. ProgramA is use to control ProgramB. When ProgramB received disconnect notice, ProgramA will try to load ProgramB. The problem is that ProgramB will not reload if the old process for ProgramB is still active in task manager. so the script is being use to detect the disconnect notice box (one small okay box with color 0x7b6b4a) and once detect send "Enter" to acknowledge the notice so it will close properly. Once ProgramB is closed ProgramA has 30 second to reload ProgramB. ProgramA has already been programmed to reload ProgramB every 30 second after receiving disconnect notice. I just need to be able to acknowledge the disconnect before 30 second ends so ProgramB can be reload. Dim $ClickMouse, $MousePrimary, $MouseSecondary, $ExitKeyDim $Color, $Left, $Top, $Right, $Bottom, $SearchResult, $CheckSwap$CheckSwap = RegRead("HKEY_CURRENT_USER\Control Panel\Mouse", "SwapMouseButtons")If $CheckSwap = 1 Then $MousePrimary = "left" $MouseSecondary = "right"Else $MousePrimary = "left" $MouseSecondary = "right"EndIf; ************************************************* ;; Change your settings here ;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv ;$ExitKey = "{ESC}"$Color = 0x7b6b4a$Left = 825$Top = 542$Right = 0$Bottom = 0; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ;; Change your settings here ;; ************************************************* ;HotKeySet($ExitKey, '_Exit')While 1 $SearchResult = PixelSearch($Left, $Top, $Right, $Bottom, $Color) If Not @error Then send("{enter}") sleep(5000) EndIfWEndFunc _Exit() ExitEndFunc Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted August 28, 2010 Share Posted August 28, 2010 Hi and Welcome to the forums! There's nothing wrong with that code, run it and see for yourself. If all that mouse-stuff is for MouseClick() then you should remove it all and use "primary" and "secondary". See helpfile. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
seandisanti Posted August 28, 2010 Share Posted August 28, 2010 $CheckSwap = RegRead("HKEY_CURRENT_USER\Control Panel\Mouse", "SwapMouseButtons") If $CheckSwap = 1 Then $MousePrimary = "left" $MouseSecondary = "right" Else $MousePrimary = "left" $MouseSecondary = "right" EndIf just for the record you may want to have diff values based on the condition if you do proceed with this code Link to comment Share on other sites More sharing options...
PowNoob Posted August 28, 2010 Author Share Posted August 28, 2010 This is what i have ATM. The disconnect confirmation box comes up in the middle of my screen. I tested by ending the connection on ProgramB and still the script does not send "Enter" key to acknowledge the disconnect box. Note; i searched and was not able to locate the info i'm looking for. How can i double check to ensure i have the correct pixel coor?Dim $ExitKeyDim $Color, $Left, $Top, $Right, $Bottom, $SearchResult, $CheckSwap; ************************************************* ;; Change your settings here ;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv ;$ExitKey = "{ESC}"$Color = 0x7b6b4a$Left = 825$Top = 542$Right = 0$Bottom = 0; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ;; Change your settings here ;; ************************************************* ;HotKeySet($ExitKey, '_Exit')While 1 $SearchResult = PixelSearch($Left, $Top, $Right, $Bottom, $Color) If Not @error Then send("{enter}") sleep(5000) EndIfWEndFunc _Exit() ExitEndFunc Link to comment Share on other sites More sharing options...
Realm Posted August 28, 2010 Share Posted August 28, 2010 (edited) Dim $ExitKey Dim $Color, $Left, $Top, $Right, $Bottom, $SearchResult, $CheckSwap ; ************************************************* ; ; Change your settings here ; ; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv ; $ExitKey = "{ESC}" $Color = 0x7b6b4a $Left = 825 $Top = 542 $Right = 0;<<<<<<<<<<<<<<Pixelsearch needs a region, like a box $Bottom = 0;<<<<<<<<<<<<<<Pixelsearch needs a region, like a box ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ; ; Change your settings here ; ; ************************************************* ; HotKeySet($ExitKey, '_Exit') While 1 $SearchResult = PixelSearch($Left, $Top, $Right, $Bottom, $Color) If Not @error Then send("{enter}") sleep(5000) EndIf WEnd Func _Exit() Exit EndFunc If you want to check a specific point try this: Dim $ExitKey Dim $Color, $Left, $Top, $Right, $Bottom, $SearchResult, $CheckSwap ; ************************************************* ; ; Change your settings here ; ; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv ; $ExitKey = "{ESC}" $Color = 0x7b6b4a $Left = 825 $Top = 542 ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ; ; Change your settings here ; ; ************************************************* ; HotKeySet($ExitKey, '_Exit') PixelGetColor While 1 If PixelGetColor($Left,$Top)=8088394 Then ;decimal value for your color send("{enter}") sleep(5000) EndIf WEnd Func _Exit() Edited August 28, 2010 by Realm My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted August 28, 2010 Share Posted August 28, 2010 (edited) Run AU3Info from the Tools menu in SciTE (to get the right color). Edited August 28, 2010 by AdmiralAlkex .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
PowNoob Posted August 28, 2010 Author Share Posted August 28, 2010 Dim $ExitKey Dim $Color, $Left, $Top, $Right, $Bottom, $SearchResult, $CheckSwap ; ************************************************* ; ; Change your settings here ; ; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv ; $ExitKey = "{ESC}" $Color = 0x7b6b4a $Left = 825 $Top = 542 $Right = 0;<<<<<<<<<<<<<<Pixelsearch needs a region, like a box $Bottom = 0;<<<<<<<<<<<<<<Pixelsearch needs a region, like a box ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ; ; Change your settings here ; ; ************************************************* ; HotKeySet($ExitKey, '_Exit') While 1 $SearchResult = PixelSearch($Left, $Top, $Right, $Bottom, $Color) If Not @error Then send("{enter}") sleep(5000) EndIf WEnd Func _Exit() Exit EndFunc If you want to check a specific point try this: Dim $ExitKey Dim $Color, $Left, $Top, $Right, $Bottom, $SearchResult, $CheckSwap ; ************************************************* ; ; Change your settings here ; ; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv ; $ExitKey = "{ESC}" $Color = 0x7b6b4a $Left = 825 $Top = 542 ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ; ; Change your settings here ; ; ************************************************* ; HotKeySet($ExitKey, '_Exit') PixelGetColor While 1 If PixelGetColor($Left,$Top)=8088394 Then ;decimal value for your color send("{enter}") sleep(5000) EndIf WEnd Func _Exit() an error came up Link to comment Share on other sites More sharing options...
Realm Posted August 28, 2010 Share Posted August 28, 2010 (edited) If you were trying my second example, note that I accidentally cut of your _Exit() function, if you pasted as it is written that would most likely be your error. if you corrected it, than next time share the error you get, so we can help you easier. my corrected example Dim $ExitKey Dim $Color, $Left, $Top, $Right, $Bottom, $SearchResult, $CheckSwap ; ************************************************* ; ; Change your settings here ; ; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv ; $ExitKey = "{ESC}" $Color = 0x7b6b4a $Left = 825 $Top = 542 ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ; ; Change your settings here ; ; ************************************************* ; HotKeySet($ExitKey, '_Exit') PixelGetColor While 1 If PixelGetColor($Left,$Top)=8088394 Then send("{enter}") sleep(5000) EndIf WEnd Func _Exit() Exit EndFunc Edited August 28, 2010 by Realm My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. Link to comment Share on other sites More sharing options...
PowNoob Posted August 28, 2010 Author Share Posted August 28, 2010 i found a solution ^^ instead of doing a Send or MouseClick, i did a taskkill and kill ProgramB process once PixelGetColor match the color and it worked great Thanks for all the help Link to comment Share on other sites More sharing options...
PowNoob Posted August 29, 2010 Author Share Posted August 29, 2010 (edited) i tried adding the following code to help reduce memory each time ProgramB reload but no success. Can someone help? _ReduceMemory(ProcessExists(@ScriptName)) 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() new code i'm using Dim $ExitKey HotKeySet($ExitKey, '_Exit') $ExitKey = "{ESC}" While 1 If PixelGetColor(808,545)=0x73634A Then ;decimal value for your color Run('TASKKILL /F /PID ' & ProcessExists('ProgramB')) sleep(20000) Run(@ComSpec & ' /c programB', @DesktopCommonDir, @SW_HIDE) sleep(300) EndIf sleep (300) WEnd Func _Exit() Exit EndFunc Edited August 29, 2010 by PowNoob Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now