无聊学学AHK–窗口剪切播放器

想在打游戏、敲代码、分析数据、写报告……时候可以一边追剧看番。所以写了款小工具,功能不多,但是很实用,主要用来剪切其他窗口的画面并投放:

1.界面很简洁

2.自动调节画面大小

3.支持缩放

4.支持透明度调节

5.支持鼠标穿透

……

无聊学学AHK–窗口剪切播放器

以上动图,具体代码如下,还有很多未完善内容,如有更好的建议欢迎指出,供娱乐 😉

;~ 快捷键说明:
;~ WIN+鼠标左键:按住win键的同时按住鼠标左键框选需要剪切播放的画面区域
;~ WIN+`:win键加q左上角的按键,主要用于切换功能,在仅置顶->置顶并支持鼠标穿透->返回原画面->置顶……间循环。

#SingleInstance, Force
OnExit, LiveClose
CoordMode, ToolTip, Screen
ListLines, Off
tp:=16
,VarSetCapacity(buf, 16)
,NumPut(1, buf)
,NumPut(VarSetCapacity(bi, 40), bi)
,NumPut(A_ScreenHeight, NumPut(A_ScreenWidth, bi, 4, "UInt"))
,NumPut(32, NumPut(1, bi, 12, "UShort"))

Sourcehwnd:=DllCall("Gdiplus\GdiplusStartup", "UIntP", 0, "UInt", &buf, "UInt", 0)
hDIBSection := DllCall("CreateDIBSection", "UInt", 0, "UInt", &bi, "UInt", 0, "UInt", 0, "UInt", 0, "UInt", 0)
hCompatibleDC:=DllCall("CreateCompatibleDC", "UInt", DllCall("GetDC", "UInt", 0))
hObject:= DllCall("SelectObject", "UInt", hCompatibleDC, "UInt", hDIBSection)
DllCall("Gdiplus\GdipCreateFromHDC", "UInt", hCompatibleDC, "UIntP", pGdip)
DllCall("Gdiplus\GdipCreatePen1", "UInt", 0xFF00FF00, "Float", 2, "Int", 2, "PtrP", pPen)
return


#LButton::
if !selectionFlag
{
	Gui, Live: +HwndLivehwnd +AlwaysOnTop +LastFound -Caption +Resize -Border
	Gui, Live: Color, 66CCFF
	WinSet, Transparent, 255
	Gui, Selection: +E0x80000 +AlwaysOnTop +ToolWindow -DPIScale hwndSelectionhwnd
	CoordMode, Mouse, Relative
	MouseGetPos, o_x, o_y
	CoordMode, Mouse, Screen
	MouseGetPos, r_x, r_y, Sourcehwnd
	Gui, Selection: Show, NA
	Loop
	{
		if !GetKeyState("LButton", "P")
			break
		MouseGetPos, r_xx, r_yy
		DllCall("Gdiplus\GdipDrawRectangle", "UInt", pGdip, "UInt", pPen, "Float", Min(r_x, r_xx), "Float", Min(r_y, r_yy), "Float", Abs(r_xx - r_x), "Float", Abs(r_yy - r_y))
		DllCall("UpdateLayeredWindow", "UInt", Selectionhwnd, "UInt", 0, "UInt", &Temppt
			 , "UInt64*", A_ScreenWidth|A_ScreenHeight<<32, "UInt", hCompatibleDC, "UInt64*", 0, "UInt", 0
			 , "UInt*", 255<<16|1<<24, "UInt", 2)
		DllCall("Gdiplus.dll\GdipGraphicsClear", "Ptr", pGdip, "UInt", 0x00FFFFFF)
	}
	CoordMode, Mouse, Relative
	MouseGetPos, o_xx, o_yy
	o_w:=Abs(o_xx-o_x), o_h:=Abs(o_yy-o_y), o_p:=o_w/o_h
	WinGetPos, ow_x, ow_y, ow_w, ow_h, ahk_id %Sourcehwnd%
	WinMove, ahk_id %Sourcehwnd%, , A_ScreenWidth, A_ScreenHeight
	WinSet, ExStyle, ^0x80, ahk_id %Sourcehwnd%
	Gui, Selection: Destroy
	Gui, Live: Show, % "w"o_w " h"o_h " x"r_x " y"r_y, Live
	WinSet, ExStyle, -0x20, ahk_id %Livehwnd%
	hWindowDC:= DllCall("GetWindowDC", "UInt", Sourcehwnd)
	hLiveDC:= DllCall("GetDC", "UInt", Livehwnd)
	DllCall("Gdi32\SetStretchBltMode", "UInt", hLiveDC, "UInt", 4)
	
	OnMessage(0x201, "WIN_MOVE")
	OnMessage(0x203, "WM_LBUTTONDBLCLK")
	OnMessage(0x206, "WM_RBUTTONDBLCLK")
	OnMessage(0x6, "WM_ACTIVATE")
	SetTimer, BitBlt, 10
	selectionFlag:=1
	ToolTip 仅置顶, % r_x + o_w, % r_y + o_h
	SetTimer, RemoveToolTip, -1000
}
return

#`::
	Flag := (!Flag || Flag = 3) ? 1 : Flag + 1
	if (Flag = 1)
	{
		WinGetPos, r_x, r_y, , , ahk_id %Livehwnd%
		WinSet, ExStyle, +0x20, ahk_id %Livehwnd%
		ToolTip 置顶+鼠标穿透, % r_x + w, % r_y + h
		SetTimer, RemoveToolTip, -1000
	}
	else if (Flag = 2)
	{
		WinGetPos, r_x, r_y, , , ahk_id %Livehwnd%
		Gui, Live: Hide
		WinMove, ahk_id %Sourcehwnd%, , ow_x, ow_y, ow_w, ow_h
		WinSet, ExStyle, -0x80, ahk_id %Sourcehwnd%
		WinActivate, ahk_id %Sourcehwnd%
		SetTimer, BitBlt, Off
		selectionFlag := 0
		ToolTip 关闭, % r_x + w, % r_y + h
		SetTimer, RemoveToolTip, -1000
	}
	else if (Flag = 3)
	{
		WinMove, ahk_id %Sourcehwnd%, , A_ScreenWidth, A_ScreenHeight
		Gui, Live: Show, % "w"w " h"h, Live
		WinSet, ExStyle, -0x20, ahk_id %Livehwnd%
		WinSet, ExStyle, +0x80, ahk_id %Sourcehwnd%
		SetTimer, BitBlt, 0
		selectionFlag := 1
		ToolTip 仅置顶, % r_x + w, % r_y + h
		SetTimer, RemoveToolTip, -1000
	}
return

#IfWinExist, Live

#WheelDown::
#WheelUp::
	WinSet, Transparent, % 16*(A_ThisHotkey = "#WheelDown" ? tp > 0 ? --tp : tp : tp < 16 ? ++tp : tp), ahk_id %Livehwnd%
return

BitBlt:
DllCall("StretchBlt", "UInt", hLiveDC, "Int", t_x, "Int", t_y, "Int", t_w, "Int", t_h
					, "UInt", hWindowDC, "Int", o_x < o_xx ? o_x : o_xx, "Int", o_y < o_yy ? o_y : o_yy, "Int", o_w, "Int", o_h, "UInt", 0xCC0020)
return

RemoveToolTip:
	ToolTip
return

LiveClose:
	WinMove, ahk_id %Sourcehwnd%, , ow_x, ow_y, ow_w, ow_h
	WinSet, ExStyle, -0x80, ahk_id %Sourcehwnd%
	WinActivate, ahk_id %Sourcehwnd%
	SetTimer, BitBlt, Off
	ExitApp
return
WM_ACTIVATE(l, p)
{
	global
	if (l = 1)
	{
		WinActivate, ahk_id %Sourcehwnd%
		Sleep 100
		WinActivate, ahk_id %Livehwnd%
	}
}

WIN_MOVE()
{
    PostMessage, 0xA1, 2
}

WM_LBUTTONDBLCLK()
{
	global
	WinMove, Live, , , , o_w + 14, o_h + 14
}

WM_RBUTTONDBLCLK()
{
	global
	WinMove, Live, , , , w/h < o_p ? w + 14 : h*o_p + 14, w/h < o_p ? w/o_p + 14 : h + 14
}

LiveGuiSize(GuiHwnd, EventInfo, Width, Height)
{
	global
	Gui, Live: Color, 66CCFF
	w := width, h := height
	if ((w + 1)/h > o_p) && ((w - 1)/h > o_p)
		t_x := (w - h*o_p)/2, t_y := 0, t_w := h*o_p, t_h := h
	else
		t_x := 0, t_y := (h - w/o_p)/2, t_w := w, t_h := w/o_p
}

 

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA捐赠
共{{data.count}}人
人已捐赠
其他

随机播放本地电影 [脚本],[AutoHotkey],[按空格键随机播放本地电影视频文件],[ahk],[2019年1月18日5时33分],[作者 徐晓亮 aahk],[腾讯QQ号595076941]

2019-1-18 15:20:40

其他

一键设置系统启动后自动运行此脚本 AutoRunSet v1.0 By BoAi

2019-2-21 13:12:18

5 条回复 A文章作者 M管理员
  1. 悠然生活

    能截出窗口,但是不能播放视频,音频有。

  2. ahker

    NB,有一款软件叫OnTopReplica有类似的功能,但是win10有些不兼容.

  3. 那个小兵

    好东西。

  4. redoceans

    截完了就可以保留了。

  5. doctorzhang

    搞不懂

个人中心
购物车
优惠劵
有新私信 私信列表
搜索