매크로

조회 수 2376 추천 3 댓글 14

?

마지막이야기님이 요청하신 스크린샷 캡춰방법입니다.

쪽지로 드릴까하다가 또 다른분들도 찾으실까봐 팁으로 남겨드립니다.

사용법만 간단히 적어드릴께요~

?

?

CaptureScreen(2, False, sFileTo,100)

?

?

캡춰가 필요한 부분에서?위 명령어 사용하시면되고요

절취선 아래부분의 코드는 스크립트 맨 아래 붙여넣기 해두시면됩니다.

?

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


CaptureScreen(aRect = 0, bCursor = False, sFile = "", nQuality = "")
{
?If !aRect
?{
?SysGet, nL, 76
?SysGet, nT, 77
?SysGet, nW, 78
?SysGet, nH, 79
?}
?Else If aRect = 1
?WinGetPos, nL, nT, nW, nH, A
?Else If aRect = 2
?{
?WinGet, hWnd, ID, A
?VarSetCapacity(rt, 16, 0)
?DllCall("GetClientRect" , "Uint", hWnd, "Uint", &rt)
?DllCall("ClientToScreen", "Uint", hWnd, "Uint", &rt)
?nL := NumGet(rt, 0, "int")
?nT := NumGet(rt, 4, "int")
?nW := NumGet(rt, 8)
?nH := NumGet(rt,12)
?}
?Else If aRect = 3
?{
?VarSetCapacity(mi, 40, 0)
?DllCall("GetCursorPos", "int64P", pt)
?DllCall("GetMonitorInfo", "Uint", DllCall("MonitorFromPoint", "int64", pt, "Uint", 2), "Uint", NumPut(40,mi)-4)
?nL := NumGet(mi, 4, "int")
?nT := NumGet(mi, 8, "int")
?nW := NumGet(mi,12, "int") - nL
?nH := NumGet(mi,16, "int") - nT
?}
?Else
?{
?StringSplit, rt, aRect, `,, %A_Space%%A_Tab%
?nL := rt1
?nT := rt2
?nW := rt3 - rt1
?nH := rt4 - rt2
?znW := rt5
?znH := rt6
?}

?mDC := DllCall("CreateCompatibleDC", "Uint", 0)
?hBM := CreateDIBSection(mDC, nW, nH)
?oBM := DllCall("SelectObject", "Uint", mDC, "Uint", hBM)
?hDC := DllCall("GetDC", "Uint", 0)
?DllCall("BitBlt", "Uint", mDC, "int", 0, "int", 0, "int", nW, "int", nH, "Uint", hDC, "int", nL, "int", nT, "Uint", 0x40000000 | 0x00CC0020)
?DllCall("ReleaseDC", "Uint", 0, "Uint", hDC)
?If bCursor
?CaptureCursor(mDC, nL, nT)
?DllCall("SelectObject", "Uint", mDC, "Uint", oBM)
?DllCall("DeleteDC", "Uint", mDC)
?If znW && znH
?hBM := Zoomer(hBM, nW, nH, znW, znH)
?If sFile = 0
?SetClipboardData(hBM)
?Else Convert(hBM, sFile, nQuality), DllCall("DeleteObject", "Uint", hBM)
}

CaptureCursor(hDC, nL, nT)
{
?VarSetCapacity(mi, 20, 0)
?mi := Chr(20)
?DllCall("GetCursorInfo", "Uint", &mi)
?bShow? := NumGet(mi, 4)
?hCursor := NumGet(mi, 8)
?xCursor := NumGet(mi,12)
?yCursor := NumGet(mi,16)

?VarSetCapacity(ni, 20, 0)
?DllCall("GetIconInfo", "Uint", hCursor, "Uint", &ni)
?xHotspot := NumGet(ni, 4)
?yHotspot := NumGet(ni, 8)
?hBMMask? := NumGet(ni,12)
?hBMColor := NumGet(ni,16)

?If bShow
?DllCall("DrawIcon", "Uint", hDC, "int", xCursor - xHotspot - nL, "int", yCursor - yHotspot - nT, "Uint", hCursor)
?If hBMMask
?DllCall("DeleteObject", "Uint", hBMMask)
?If hBMColor
?DllCall("DeleteObject", "Uint", hBMColor)
}

Zoomer(hBM, nW, nH, znW, znH)
{
?mDC1 := DllCall("CreateCompatibleDC", "Uint", 0)
?mDC2 := DllCall("CreateCompatibleDC", "Uint", 0)
?zhBM := CreateDIBSection(mDC2, znW, znH)
?oBM1 := DllCall("SelectObject", "Uint", mDC1, "Uint",? hBM)
?oBM2 := DllCall("SelectObject", "Uint", mDC2, "Uint", zhBM)
?DllCall("SetStretchBltMode", "Uint", mDC2, "int", 4)
?DllCall("StretchBlt", "Uint", mDC2, "int", 0, "int", 0, "int", znW, "int", znH, "Uint", mDC1, "int", 0, "int", 0, "int", nW, "int", nH, "Uint", 0x00CC0020)
?DllCall("SelectObject", "Uint", mDC1, "Uint", oBM1)
?DllCall("SelectObject", "Uint", mDC2, "Uint", oBM2)
?DllCall("DeleteDC", "Uint", mDC1)
?DllCall("DeleteDC", "Uint", mDC2)
?DllCall("DeleteObject", "Uint", hBM)
?Return zhBM
}

Convert(sFileFr = "", sFileTo = "", nQuality = "")
{
?If sFileTo? =
?sFileTo := A_ScriptDir . "\screen.bmp"
?SplitPath, sFileTo, , sDirTo, sExtTo, sNameTo

?If Not hGdiPlus := DllCall("LoadLibrary", "str", "gdiplus.dll")
?Return sFileFr+0 ? SaveHBITMAPToFile(sFileFr, sDirTo . "\" . sNameTo . ".bmp") : ""
?VarSetCapacity(si, 16, 0), si := Chr(1)
?DllCall("gdiplus\GdiplusStartup", "UintP", pToken, "Uint", &si, "Uint", 0)

?If !sFileFr
?{
?DllCall("OpenClipboard", "Uint", 0)
?If DllCall("IsClipboardFormatAvailable", "Uint", 2) && (hBM:=DllCall("GetClipboardData", "Uint", 2))
?DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", "Uint", hBM, "Uint", 0, "UintP", pImage)
?DllCall("CloseClipboard")
?}
?Else If sFileFr Is Integer
?DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", "Uint", sFileFr, "Uint", 0, "UintP", pImage)
?Else DllCall("gdiplus\GdipLoadImageFromFile", "Uint", Unicode4Ansi(wFileFr,sFileFr), "UintP", pImage)

?DllCall("gdiplus\GdipGetImageEncodersSize", "UintP", nCount, "UintP", nSize)
?VarSetCapacity(ci,nSize,0)
?DllCall("gdiplus\GdipGetImageEncoders", "Uint", nCount, "Uint", nSize, "Uint", &ci)
?Loop, % nCount
?If InStr(Ansi4Unicode(NumGet(ci,76*(A_Index-1)+44)), "." . sExtTo)
?{
?pCodec := &ci+76*(A_Index-1)
?Break
?}
?If InStr(".JPG.JPEG.JPE.JFIF", "." . sExtTo) && nQuality<>"" && pImage && pCodec
?{
?DllCall("gdiplus\GdipGetEncoderParameterListSize", "Uint", pImage, "Uint", pCodec, "UintP", nSize)
?VarSetCapacity(pi,nSize,0)
?DllCall("gdiplus\GdipGetEncoderParameterList", "Uint", pImage, "Uint", pCodec, "Uint", nSize, "Uint", &pi)
?Loop, % NumGet(pi)
?If NumGet(pi,28*(A_Index-1)+20)=1 && NumGet(pi,28*(A_Index-1)+24)=6
?{
?pParam := &pi+28*(A_Index-1)
?NumPut(nQuality,NumGet(NumPut(4,NumPut(1,pParam+0)+20)))
?Break
?}
?}

?If pImage
?pCodec ? DllCall("gdiplus\GdipSaveImageToFile", "Uint", pImage, "Uint", Unicode4Ansi(wFileTo,sFileTo), "Uint", pCodec, "Uint", pParam) : DllCall("gdiplus\GdipCreateHBITMAPFromBitmap", "Uint", pImage, "UintP", hBitmap, "Uint", 0) . SetClipboardData(hBitmap), DllCall("gdiplus\GdipDisposeImage", "Uint", pImage)

?DllCall("gdiplus\GdiplusShutdown" , "Uint", pToken)
?DllCall("FreeLibrary", "Uint", hGdiPlus)
}

CreateDIBSection(hDC, nW, nH, bpp = 32, ByRef pBits = "")
{
?NumPut(VarSetCapacity(bi, 40, 0), bi)
?NumPut(nW, bi, 4)
?NumPut(nH, bi, 8)
?NumPut(bpp, NumPut(1, bi, 12, "UShort"), 0, "Ushort")
?NumPut(0,? bi,16)
?Return DllCall("gdi32\CreateDIBSection", "Uint", hDC, "Uint", &bi, "Uint", 0, "UintP", pBits, "Uint", 0, "Uint", 0)
}

SaveHBITMAPToFile(hBitmap, sFile)
{
?DllCall("GetObject", "Uint", hBitmap, "int", VarSetCapacity(oi,84,0), "Uint", &oi)
?hFile:= DllCall("CreateFile", "Uint", &sFile, "Uint", 0x40000000, "Uint", 0, "Uint", 0, "Uint", 2, "Uint", 0, "Uint", 0)
?DllCall("WriteFile", "Uint", hFile, "int64P", 0x4D42|14+40+NumGet(oi,44)<<16, "Uint", 6, "UintP", 0, "Uint", 0)
?DllCall("WriteFile", "Uint", hFile, "int64P", 54<<32, "Uint", 8, "UintP", 0, "Uint", 0)
?DllCall("WriteFile", "Uint", hFile, "Uint", &oi+24, "Uint", 40, "UintP", 0, "Uint", 0)
?DllCall("WriteFile", "Uint", hFile, "Uint", NumGet(oi,20), "Uint", NumGet(oi,44), "UintP", 0, "Uint", 0)
?DllCall("CloseHandle", "Uint", hFile)
}

SetClipboardData(hBitmap)
{
?DllCall("GetObject", "Uint", hBitmap, "int", VarSetCapacity(oi,84,0), "Uint", &oi)
?hDIB := DllCall("GlobalAlloc", "Uint", 2, "Uint", 40+NumGet(oi,44))
?pDIB := DllCall("GlobalLock", "Uint", hDIB)
?DllCall("RtlMoveMemory", "Uint", pDIB, "Uint", &oi+24, "Uint", 40)
?DllCall("RtlMoveMemory", "Uint", pDIB+40, "Uint", NumGet(oi,20), "Uint", NumGet(oi,44))
?DllCall("GlobalUnlock", "Uint", hDIB)
?DllCall("DeleteObject", "Uint", hBitmap)
?DllCall("OpenClipboard", "Uint", 0)
?DllCall("EmptyClipboard")
?DllCall("SetClipboardData", "Uint", 8, "Uint", hDIB)
?DllCall("CloseClipboard")
}

Unicode4Ansi(ByRef wString, sString)
{
?nSize := DllCall("MultiByteToWideChar", "Uint", 0, "Uint", 0, "Uint", &sString, "int", -1, "Uint", 0, "int", 0)
?VarSetCapacity(wString, nSize * 2)
?DllCall("MultiByteToWideChar", "Uint", 0, "Uint", 0, "Uint", &sString, "int", -1, "Uint", &wString, "int", nSize)
?Return &wString
}

Ansi4Unicode(pString)
{
?nSize := DllCall("WideCharToMultiByte", "Uint", 0, "Uint", 0, "Uint", pString, "int", -1, "Uint", 0, "int",? 0, "Uint", 0, "Uint", 0)
?VarSetCapacity(sString, nSize)
?DllCall("WideCharToMultiByte", "Uint", 0, "Uint", 0, "Uint", pString, "int", -1, "str", sString, "int", nSize, "Uint", 0, "Uint", 0)
?Return sString
}

?


  • profile
    외치기 2014.12.03 08:52

    제가 알기론 캡쳐스크린은 오토핫키 버전에 영향을 받는데 이건 어느버전용인가요?

  • 마지막이야기 2014.12.03 13:19
    정확히 L - Ansi 버전이네요
  • 호로록뚝딱 2014.12.03 19:27
    L버전 B버전 둘다 사용됩니다.
    제가 둘다 쓰고있거든요~
  • profile
    외치기 2014.12.03 21:30
    안시버전용 유니코드버전용이 따로있어서 여쭤봤습니다.
    지금보니 안시용같네요.
  • 마지막이야기 2014.12.03 11:56
    L버전에서 되는거 같아요 ㅎ


    정말 너무너무 감사합니다!!!

  • 호로록뚝딱 2014.12.03 19:31
    도움되셨다니 다행이네요~
    저도 오핫키 첨 입문할땐 알려주는곳없어 힘들었었죠 ㅋ
    간단한건데 도통 다들 폐쇠적이라...
  • 마지막이야기 2014.12.04 11:46
    네 ㅎㅎ

    테일스타 덕분에 많이 배웁니다 ㅎㅎ

    다시한번 감사드려용 ^^
  • 마지막이야기 2014.12.09 13:23

    비활성에서 질문 하나 드리겠습니다 ㅎ


    지니모션의 좌표를 X, Y, X2, Y2 로 따서요


    CaptureScreen( "%X%,%Y%,%X2%,%Y2%" , False, sFileTo,100)? 이런식으로 좌표지정 캡쳐하면 안되더군요 ㅠㅠ


    범위를 숫자로 하면 되는데


    캡쳐스크린 범위지정은 좌표는 문자를 인식 못하는거 같아요 ;


    혹시 비활성에서 하는 방법 따로 있으신가요? ㅎ

  • 생물 2014.12.09 22:32
    http://www.autohotkey.co.kr/cgi/board.php?bo_table=tip&wr_id=272
    %빼고 해보세요
  • 마지막이야기 2014.12.09 23:01

    %빼고 해도 안됬는데 링크 가서 보고 해결 했습니다 ^^

    pos=%X%,%Y%,%X2%,%Y2%
    CaptureScreen(pos, 0, sFileTo,100)

    이렇게 하니 되네요 ^^

    몇일 헤매던거 생물님 덕분에 해결했습니다 ㅎ

    정말 감사합니다 ㅎㅎ 오토핫키 참 어렵네요 ㅠ

  • 접무 2014.12.11 13:03

    오 감사합니다 ㅠ

    매번 복잡하게 했는데 깔끔하네요 ㅎㅎ

  • valum 2015.01.10 16:54

    감사합니다 잘쓰겠습니다

  • 핸콕 2015.03.23 12:36

    호로록님 자료 감사합니다^^?

    @외치기 @숨어야산다 님 핼프미^^;;


    스크린샷을 저장할때. 날짜명으로 저장되게 변수를 넣고 싶은데..잘모르겠네요^^;

    sFileTo := A_ScriptDir . "\screen.bmp"

    이부분에서 스크린샷 파일명을 screen이 아닌 변수로 넣을려면 어떻게 해야 할지..조언좀 부탁드립니다^^

  • 핸콕 2015.03.24 08:12
    일단..그대로 저장하고나서, filecopy, filedelete로 해결했습니다~ ^^;

List of Articles
분류 제목 글쓴이 최근변경 추천
질문 Hide 관련 질문 5 파더 2014.11.29 0/0
자유 에휴...고생해서 만든것들이 다 날라갔어요 ㅠㅠ 2 flem 2014.12.01 0/0
자유 오늘도 그냥 지나가기 심심해서 팁 하나 올려요. 이미... 2 swksd 2014.11.30 0/0
질문 변수에 관한 질문 5 파더 2014.11.30 0/0
질문 몬스터 길들이기 패치후에. 4 페르니코 2017.12.18 0/0
질문 스크립트 좀더 간략하게 작성방법이 있을까요. 8 우후훅 2014.12.04 0/0
질문 비활성마우스클릭 질문드려요 단키와 합성키 12 성인남자 2014.12.02 0/0
정보 그리기 / DRAW / GDIP 화면에 선 도형 그리기 (예제) 3 따기따기 2014.12.12 0/0
질문 지니모션은 인터넷에 돌아다니는거아무거나사용해도되... 2 튀니지사람들 2014.12.02 0/0
질문 혹시 1004 매크로 1920 * 1080 해상도를 세나에 맞춰 ... 인사왕바이킹 2014.12.01 0/0
질문 어떤 이미지를 찾을때 같은 이미지가 있을때 대한 처리 7 프로구라머 2014.12.07 0/0
정보 스크린샷 캡춰방법 (마지막이야기님 요청) 14 호로록뚝딱 2015.03.24 3/0
질문 리스트박스 관련질문 4 파더 2014.12.03 0/0
질문 체크박스 if 에대해서 6 파더 2014.12.04 0/0
질문 오토핫키 이미지서치좀 봐주세요ㅡ모비즌연동 8 뀨잉여기좋아 2014.12.05 0/0
질문 1004매크로 1 dlalsrb86 2014.12.04 0/0
자유 오토핫키컴파일 이후 Themida 패킹 사용하면되는건가요? 파더 2014.12.04 0/0
자유 아주 간단한건데.. 하면 이쁜 gui 색입히기... 2 로우얄 2017.12.19 0/0
질문 VMProtect Unpack 17 외치기 2017.03.19 0/0
질문 와 ,,,핫오토키는 뭔가여... 3 찬쓰찬쓰 2014.12.12 1/0
Board Pagination Prev 1 ... 67891011121314 ... 209 Next
/ 209

전체 최신 인기글

전체 주간 인기글