autohotkey 热键_创建一个热键以使用AutoHotkey将Windows调整为特定大小

本文介绍了如何使用AutoHotkey脚本来创建热键,以便快速将窗口调整到特定宽度、高度或同时调整两者。这对于Web开发者进行页面设计测试尤其方便。通过自定义热键,比如Win+Alt+U,可以轻松地将窗口尺寸调整为800x600或其他预设尺寸。
摘要由CSDN通过智能技术生成
autohotkey 热键

autohotkey 热键

Since I spend a large amount of my time testing out applications, taking screenshots, and doing web development, I’m constantly needing to resize windows to various sizes—so I’ve put together an AutoHotkey function that does it for me.

由于我花费大量时间测试应用程序,截屏并进行Web开发,因此我一直需要将窗口调整为各种大小,因此我组合了一个AutoHotkey函数来为我完成此工作。

We’re going to assume that you’ve already downloaded and installed AutoHotkey, and you’ve got some type of idea how it all works. If you don’t, you might want to read through their tutorial.

我们将假设您已经下载并安装了AutoHotkey ,并且您已经了解了它们如何工作。 如果您不这样做,则可能需要通读他们的教程

场景 (The Scenario)

Here’s a sample video that shows the script in action, so you can understand what we’re going to be creating today. The basic idea is that we’ll be resizing windows to specific dimensions, or only resizing by either width or height while leaving the other the same.

这是一个示例视频,显示了正在运行的脚本,因此您可以了解我们今天将要创建的内容。 基本思想是,我们将窗口尺寸调整为特定尺寸,或者仅按宽度或高度调整尺寸,而使其他尺寸保持不变。

创建AutoHotkey脚本 (Create the AutoHotkey Script)

You’ll want to start out by creating a blank AutoHotkey script and putting the following code into it. This is the function that we’ll use to resize windows with some hotkey definitions later on. You can, of course, put this function into your existing script as well.

首先,您需要创建一个空白的AutoHotkey脚本并将以下代码放入其中。 稍后我们将使用此函数来调整窗口的大小,并添加一些热键定义。 当然,您也可以将此函数放入现有脚本中。

ResizeWin(Width = 0,Height = 0){  WinGetPos,X,Y,W,H,A  If %Width% = 0    Width := W

ResizeWin(Width = 0,Height = 0){WinGetPos,X,Y,W,H,A如果%Width%= 0宽度:= W

  If %Height% = 0    Height := H

如果%Height%= 0高度:= H

  WinMove,A,,%X%,%Y%,%Width%,%Height%}

WinMove,A,%X%,%Y%,%Width%,%Height%}

The “A” in the script means that it will work on the active window—you could replace that with the title of a specific window if you wanted. You’ll notice the first line in the function grabs the current width/height and X/Y position, which is then used in the script in case width/height are not set, and to leave the current X/Y position on the screen in the same place.

脚本中的“ A”表示它将在活动窗口上工作-如果需要,可以将其替换为特定窗口的标题。 您会注意到函数中的第一行抓住了当前的宽度/高度和X / Y位置,然后在脚本中使用了它们(如果未设置宽度/高度),并在屏幕上保留了当前的X / Y位置在同一个地方。

将窗口调整为特定的宽度/高度 (Resize a Window to Specific Width / Height)

image

This is perhaps the most useful function for web developers, who might want to resize a browser to specific dimensions to test out a page design. Sure, there’s loads of applications and browser plugins that do the same thing, but if you’re an AutoHotkey user all you need is a few extra lines of code to eliminate all that overhead.

对于Web开发人员来说,这可能是最有用的功能,他们可能希望将浏览器调整为特定尺寸以测试页面设计。 当然,有很多应用程序和浏览器插件可以做同样的事情,但是如果您是AutoHotkey用户,则只需要多写几行代码即可消除所有开销。

To resize to a specific width and height, you’ll want to use the function like this:

要调整为特定的宽度和高度,您将需要使用以下功能:

ResizeWin(width,height)

ResizeWin(宽度,高度)

You can then assign it to a hotkey, in this case we’ll be using Win+Alt+U as the hotkey to resize the current active window to 800×600.

然后可以将其分配给热键,在这种情况下,我们将使用Win + Alt + U作为热键将当前活动窗口的大小调整为800×600。

#!u::ResizeWin(800,600)

u!:ResizeWin(800,600)


将窗口调整为特定宽度 ( 
Resize a Window to a Specific Width)

image

You can also leave off the height parameter when calling the function to only resize the window width but not the height. This is probably less useful, but I’ve found that it works out well when you have a very large screen and want to resize a number of windows to fit side-by-side on the screen.

您也可以在调用该函数以仅调整窗口宽度而不是高度时调整高度参数。 这可能用处不大,但是我发现当您的屏幕非常大并且想要调整多个窗口的大小以在屏幕上并排放置时,效果很好。

For instance, this line would assign the Win+Alt+U hotkey to resize the window to 640 pixels wide and leave the height the same:

例如,此行将分配Win + Alt + U热键以将窗口的大小调整为640像素宽,而高度保持不变:

#!u::ResizeWin(640)

u!:ResizeWin(640)


将窗口调整为特定高度 ( 
Resize a Window to a Specific Height)

image

To resize a window to a specific height while leaving the width the same, just pass in 0 as the height parameter. For example, to resize the current window to 400 pixels tall when you press Win+Alt+U, you’d use this line:

要在不改变宽度的情况下将窗口调整为特定高度,只需将0作为height参数传入即可。 例如,要在按Win + Alt + U时将当前窗口的大小调整为400像素高,可以使用以下行:

#!u::ResizeWin(0,400)

#!u :: ResizeWin(0,400)

It’s a useful function that you can drop into your AutoHotkey script—even if you don’t need it right now, it’s probably useful to save for later. We’ve also got a downloadable version of the script you can use here:

您可以将其放入AutoHotkey脚本中,这是一个有用的功能-即使您现在不需要它,以后保存也很有用。 我们还提供了脚本的可下载版本,您可以在此处使用它:

Download ResizeWindows AutoHotkey Script from howtogeek.com

Download ResizeWindows AutoHotkey Script from howtogeek.com

翻译自: https://www.howtogeek.com/howto/28663/create-a-hotkey-to-resize-windows-to-a-specific-size-with-autohotkey/

autohotkey 热键

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值