Что нового

как Получить координаты пикселя и цвет под курсором не используя CV и Au3Info

general66

Пришел увидел наследил
Сообщения
211
Репутация
3
Боюсь разгневать вопросом "старейшин" но ...

чтоб получить координату и цвет пикселя пользуюсь CV но координат так много что периодичное обновление координат пикселей и их цвета просто утомляет, отсюда и вопрос вернее мольба о помощи возможно ли к своей GUI прикрутить что то подобное как в CV или Au3Info только совсем упрощенное , кликнул и получил в переменные координату X,Y, и цвет ,а если еще и лупа будет то это просто вершина наслаждения процессом. по любому кто то уже сталкивался с такой нуждой поделитесь наработками , а то я кроме MouseGetPos и PixelGetColor нечего не нашел
Код:
Func pix()
$pos=MouseGetPos()
$color = PixelGetColor( $pos[0],$pos[1])
MsgBox(0,'','Цвет HEX - '& Hex ($color,6) &@CRLF& 'Координаты   X- ' & $pos[0] &  '   Y- ' & $pos[1])
EndFunc

While 1
HotKeySet ("{`}","pix")
WEnd
вернее как до кучи собрать эти 2 функции, чтоб они как в CV фиксировали координаты и цвет :'( заранее благодарю за понимание


Добавлено:
Сообщение автоматически объединено:

нашел тут на форуме вот это
http://autoit-script.ru/index.php/topic,2871.msg20741.html#msg20741 -зум
http://autoit-script.ru/index.php/topic,2574.msg18598.html#msg18598 -координаты
помогите объединить
 
Автор
G

general66

Пришел увидел наследил
Сообщения
211
Репутация
3
AZJIO [?]

Втом то и беда что готовых вариантов десятки, но мне нужен скрипт который сохранял результаты в переменные -> которые используются в моем же скрипте т. е. объединить мой скрипт с тем который это может, к сожалению ни одна из готовых программ это делать не может, а мой уровень знаний не позволяет с нуля написать что то подобное знаний даже пока не хватает выдрать из Контрол Вьювера уже готовый код :'( пытаюсь из того что нашел на форуме сваять что то совсем минимальное но не получается , вот скажем есть скрипт который показывает координаты
Код:
#include <GUIConstantsEx.au3>

Opt ('MustDeclareVars',     1)
Local $action
Local $gui      = GUICreate ("", 100, 30)
Local $label    = GUICtrlCreateLabel ("", 30, 5, 80, 25)

        GUISetState (@SW_SHOW, $gui)

Func _update ()
    Local $_coord = MouseGetPos ()
    GUICtrlSetData ($label, $_coord[0] &"x"& $_coord[1])
EndFunc

While True
    $action = GUIGetMsg ()
    _update ()

    If $action = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

вот скрипт простенькой лупы
Код:
#include <GDIPlus.au3>
#include <ScreenCapture.au3>
#include <GUIConstants.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Dim $coord[2], $oldCoord[2], $pict, $hBit, $hGraph, $side = 60, $zoom = 2, $desk = WinGetPos("Program Manager")

$hGUI = GUICreate ("coord", 100, 100)
GUISetState()
_GDIPlus_Startup()
While GUIGetMsg() <> -3
    $coord = MouseGetPos()
    If $coord[0] <> $oldCoord[0] Or $coord[1] <> $oldCoord[1]  Then
        $oldCoord = $coord
        _GDIPlus_GraphicsDispose($hGraph)
        _GDIPlus_ImageDispose($hBit)
        _WinAPI_DeleteObject($pict)
        $pict = _ScreenCapture_Capture("", $coord[0] - $side/2, $coord[1] - $side/2, $coord[0] + $side/2, $coord[1] + $side/2)
        $hBit = _GDIPlus_BitmapCreateFromHBITMAP($pict)
        $hGraph = _GDIPlus_GraphicsCreateFromHWND($hGUI)
        _GDIPlus_GraphicsDrawImageRectRect($hGraph, $hBit, 0, 0, $side, $side, 1, 1, $side*$zoom, $side*$zoom)
        If $coord[0] > $desk[2] - $side*($zoom + 0.5) - 2 Then $coord[0] = $coord[0] - $side*$zoom - $side - 2
        If $coord[1] > $desk[3] - $side*($zoom + 0.5) - 2 Then $coord[1] = $coord[1] - $side*$zoom - $side - 2
        WinMove("Zoo-o-o-M", "", $coord[0] + $side/2 , $coord[1] + $side/2)
    EndIf
    Sleep(50)
WEnd
_GDIPlus_Shutdown()


как их объединить в один и научить определять цвет и все сохранять в переменные я имею в виду цвет и координаты корректно не получается не хватает знаний :stars: помогите пожалуйста
 
Автор
G

general66

Пришел увидел наследил
Сообщения
211
Репутация
3
Скажите приведенные мной выше скрипты совместимы или нет ? если да хоть намекните каким способом их объединить а то у меня не получается разнести их на форме GUI они накладываются друг на друга :(
 

AZJIO

Меценат
Меценат
Сообщения
2,879
Репутация
1,194
Код:
#include <ScreenCapture.au3>

Dim $coord[2], $oldCoord[2], $pict, $hBit, $hGraph, $side = 60, $zoom = 2, $desk = WinGetPos("Program Manager")

$hGUI = GUICreate ("coord", 100, 160)
Local $label    = GUICtrlCreateLabel ("", 30, 130, 80, 25)
GUISetState()
_GDIPlus_Startup()
While GUIGetMsg() <> -3
    $coord = MouseGetPos()
    If $coord[0] <> $oldCoord[0] Or $coord[1] <> $oldCoord[1]  Then
    GUICtrlSetData ($label, $coord[0] &"x"& $coord[1])
        $oldCoord = $coord
        _GDIPlus_GraphicsDispose($hGraph)
        _GDIPlus_ImageDispose($hBit)
        _WinAPI_DeleteObject($pict)
        $pict = _ScreenCapture_Capture("", $coord[0] - $side/2, $coord[1] - $side/2, $coord[0] + $side/2, $coord[1] + $side/2)
        $hBit = _GDIPlus_BitmapCreateFromHBITMAP($pict)
        $hGraph = _GDIPlus_GraphicsCreateFromHWND($hGUI)
        _GDIPlus_GraphicsDrawImageRectRect($hGraph, $hBit, 0, 0, $side, $side, 1, 1, $side*$zoom, $side*$zoom)
        If $coord[0] > $desk[2] - $side*($zoom + 0.5) - 2 Then $coord[0] = $coord[0] - $side*$zoom - $side - 2
        If $coord[1] > $desk[3] - $side*($zoom + 0.5) - 2 Then $coord[1] = $coord[1] - $side*$zoom - $side - 2
        WinMove("Zoo-o-o-M", "", $coord[0] + $side/2 , $coord[1] + $side/2)
    EndIf
    Sleep(50)
WEnd
_GDIPlus_Shutdown()
 
Автор
G

general66

Пришел увидел наследил
Сообщения
211
Репутация
3
AZJIO

Огромное спасибо за помощь и понимание :beer:

Подскажите я опять запутался хотел добавить горячую клавишу для закрытия окошка с лупой но она не срабатывает и окошко с первого раза не закрывается , а со второго закрываются все окна подскажите где ошибка? И еще как сделать так чтоб по нажатию кнопки проверка горячая клавиша отменялся в этом скрипте и больше не действовала? (строку с горячей клавишей удалил вызывает ошибку)
Код:
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ScreenCapture.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Поиск цвета и координат", 401, 139, 224, 114)
$Group1 = GUICtrlCreateGroup("", 8, 8, 385, 121)
$Button1 = GUICtrlCreateButton("Цвет", 315, 53, 35, 25)
$Input1 = GUICtrlCreateInput('', 123, 53, 25, 21)
$Input2 = GUICtrlCreateInput("", 156, 53, 25, 21)
$Input3 =GUICtrlCreateInput("", 59, 53, 55, 21)
$Radio1 = GUICtrlCreateRadio("Записать", 197, 56, 81, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$Input4 = GUICtrlCreateInput("", 123, 84, 25, 21)
$Input5 = GUICtrlCreateInput("", 156, 84, 25, 21)
$Input6 =GUICtrlCreateInput("", 59, 84, 55, 21)
$Radio2 = GUICtrlCreateRadio("Записать", 197, 87, 81, 17)
$Button2 = GUICtrlCreateButton("Проверка", 296, 88, 75, 25)
$Label1 = GUICtrlCreateLabel("Цвет", 72, 35, 29, 17)
$Label2 = GUICtrlCreateLabel("X", 131, 36, 11, 17)
$Label3 = GUICtrlCreateLabel("Y", 164, 36, 11, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
$Input_form1 = 0
$Input_form2 = 0
$Input_form3 = 0
$Input_form4 = 0
$Input_form5 = 0
$Input_form6 = 0
$Radio_temp1 = 0
$Radio_temp2 = 0

While 1

	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit
		Case $Button1
			If GUICtrlRead ($Radio1) = 1 Then
				$Radio_temp1 = '1'
				EndIf
			If GUICtrlRead ($Radio2) = 1 Then
				$Radio_temp2 = '1'
			EndIf

			Dim $coord[2], $oldCoord[2], $pict, $hBit, $hGraph, $side = 60, $zoom = 2, $desk = WinGetPos("Program Manager")

			$hGUI = GUICreate ("coord", 100, 160,-1,-1,-1,$WS_EX_TOPMOST)
			Local $label    = GUICtrlCreateLabel ("", 55, 130, 80, 25)
			Local $label_1    = GUICtrlCreateLabel ("", 5, 130, 45, 25)
			GUISetState()
			_GDIPlus_Startup()
			While GUIGetMsg() <> -3
				$coord = MouseGetPos()
				If $coord[0] <> $oldCoord[0] Or $coord[1] <> $oldCoord[1]  Then
				GUICtrlSetData ($label, $coord[0] &"x"& $coord[1])
					$oldCoord = $coord
					$color = PixelGetColor( $coord[0],$coord[1])
					GUICtrlSetData ($label_1, Hex ($color,6))
				If $Radio_temp1 = 1 Then
					GUICtrlSetData ($Input3, Hex ($color,6))
					GUICtrlSetData ($Input1, $coord[0])
					GUICtrlSetData ($Input2, $coord[1])
				EndIf
				If $Radio_temp2 = 1 Then
					GUICtrlSetData ($Input6, Hex ($color,6))
					GUICtrlSetData ($Input4, $coord[0])
					GUICtrlSetData ($Input5, $coord[1])
				EndIf
					_GDIPlus_GraphicsDispose($hGraph)
					_GDIPlus_ImageDispose($hBit)
						_WinAPI_DeleteObject($pict)
					$pict = _ScreenCapture_Capture("", $coord[0] - $side/2, $coord[1] - $side/2, $coord[0] + $side/2, $coord[1] + $side/2)
					$hBit = _GDIPlus_BitmapCreateFromHBITMAP($pict)
					$hGraph = _GDIPlus_GraphicsCreateFromHWND($hGUI)
					_GDIPlus_GraphicsDrawImageRectRect($hGraph, $hBit, 0, 0, $side, $side, 1, 1, $side*$zoom, $side*$zoom)
					If $coord[0] > $desk[2] - $side*($zoom + 0.5) - 2 Then $coord[0] = $coord[0] - $side*$zoom - $side - 2
					If $coord[1] > $desk[3] - $side*($zoom + 0.5) - 2 Then $coord[1] = $coord[1] - $side*$zoom - $side - 2
					WinMove("Zoo-o-o-M", "", $coord[0] + $side/2 , $coord[1] + $side/2)
				EndIf
				Sleep(50)
			WEnd
			_GDIPlus_Shutdown()
		Case $Button2
			$Input_form1 = GUICtrlRead($Input1)
			$Input_form2 = GUICtrlRead($Input2)
			$Input_form3 = GUICtrlRead($Input3)
			$Input_form4 = GUICtrlRead($Input4)
			$Input_form5 = GUICtrlRead($Input5)
			$Input_form6 = GUICtrlRead($Input6)

			MsgBox(64, "Input 1-6", $Radio1  & " /"& $Radio2 & " /"& $Input_form1 & " /"&$Input_form2 & " /"&$Input_form3 & " /"&$Input_form4 & " /"&$Input_form5 & " /"&$Input_form6)
		EndSwitch
	WEnd
 
Автор
G

general66

Пришел увидел наследил
Сообщения
211
Репутация
3
Тупик полный!!! перепробовал кучу вариантов вызова лупы из родительского окна все равно не получается заставить ее работать так как надо просто скрипт лупы не мой(для меня такой скрипт немного сложноват) большая просьба подскажите как заставить окно лупы вызываться кнопкой и закрываться горячей клавишей не закрывая родительское окно.
П.С. скрипт в спойлере в предыдущем сообщении


Добавлено:
Сообщение автоматически объединено:

Тайм аут :(
 

mr.Gbabak

Осваивающий
Сообщения
257
Репутация
23
Попробуй так:
Код:
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <ScreenCapture.au3>
HotKeySet("{F1}", "TPause")
HotKeySet("{F2}", "vyx")
HotKeySet ("1", "GetPos")
Global $Paused

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 184, 260, 500, 200)
$Button1 = GUICtrlCreateButton("ОК", 15, 150, 160, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Button2 = GUICtrlCreateButton("exit", 24, 192, 137, 25)
GUISetState(@SW_SHOW, $Form1)
#EndRegion ### END Koda GUI section ###

While 1
	$nMsg = GUIGetMsg()
	Select
		Case $nMsg = $GUI_EVENT_CLOSE
			Exit
		Case $nMsg = $Button2
			ExitLoop
		Case $nMsg = $Button1
			hGUI ($Form1)
EndSelect
WEnd

Func hGUI ($hParent = 3)

	Dim  $hGUI, $iGOEM_Opt, $coord[2], $oldCoord[2], $pict, $hBit, $hGraph, $side = 60, $zoom = 2, $desk = WinGetPos("Program Manager"), $x, $y, $hGUI, $iGOEM_Opt
	$iGOEM_Opt = Opt("GUIOnEventMode", 0)

#Region ### START Koda GUI section ### Form=
$hGUI = GUICreate("coord", 100, 260 , -1 , -1, 1, 1, $hParent)
$Button1 = GUICtrlCreateButton("ОК", 10, 160, 60, 30)
  GUISetState(@SW_DISABLE, $hParent)
    GUISetState(@SW_SHOW, $hGUI)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$iGOEM_Opt = Opt("GUIOnEventMode", 0)

Local $label    = GUICtrlCreateLabel ("", 30, 130, 80, 25)
GUISetState()
_GDIPlus_Startup()

While 1;GUIGetMsg() <> -3
	$nMsg = GUIGetMsg()
	Select
		Case $nMsg = $GUI_EVENT_CLOSE
			ExitLoop
		Case $nMsg = $Button1
			ExitLoop
			GUIDelete($hGUI)
	EndSelect
    $coord = MouseGetPos()
    If $coord[0] <> $oldCoord[0] Or $coord[1] <> $oldCoord[1]  Then
    GUICtrlSetData ($label, $coord[0] &"x"& $coord[1])
        $oldCoord = $coord
        _GDIPlus_GraphicsDispose($hGraph)
        _GDIPlus_ImageDispose($hBit)
        _WinAPI_DeleteObject($pict)
        $pict = _ScreenCapture_Capture("", $coord[0] - $side/2, $coord[1] - $side/2, $coord[0] + $side/2, $coord[1] + $side/2)
        $hBit = _GDIPlus_BitmapCreateFromHBITMAP($pict)
        $hGraph = _GDIPlus_GraphicsCreateFromHWND($hGUI)
        _GDIPlus_GraphicsDrawImageRectRect($hGraph, $hBit, 0, 0, $side, $side, 1, 1, $side*$zoom, $side*$zoom)
        If $coord[0] > $desk[2] - $side*($zoom + 0.5) - 2 Then $coord[0] = $coord[0] - $side*$zoom - $side - 2
        If $coord[1] > $desk[3] - $side*($zoom + 0.5) - 2 Then $coord[1] = $coord[1] - $side*$zoom - $side - 2
        WinMove("Zoo-o-o-M", "", $coord[0] + $side/2 , $coord[1] + $side/2)
    EndIf
    Sleep(50)
WEnd
_GDIPlus_Shutdown()

Opt("GUIOnEventMode", $iGOEM_Opt)
    GUISetState(@SW_ENABLE, $hParent)
    GUIDelete($hGUI)

EndFunc



Func GetPos ()
$coord2 = MouseGetPos ()
$x = $coord2 [0]
$y = $coord2 [1]
$cvet = PixelGetColor ($x, $y)
$cvet = Hex ($cvet)
MsgBox ( 0, "Coordinaty", ""&$x&" x "&$y&" цвет пикселя 0x"&$cvet&"")

EndFunc

Func TPause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func vyx()
		MsgBox ( 0, "Good Buy", "Выход")

	Exit
EndFunc


Могут быть ошибки в коде (я только учусь), но вроде должно работать!
 
Автор
G

general66

Пришел увидел наследил
Сообщения
211
Репутация
3
mr.Gbabak [?]
Могут быть ошибки в коде (я только учусь),

хорошее решение спасибо за пример единственное что нужно доделать это выбор кратности и размер окна самой лупы чтоб менялся автоматом при увеличении больше х2, а так все вроде работает без ошибок.
 
Верх