Printscreening with AHK - Freeze the screen!

Get help with using AutoHotkey and its commands and hotkeys
Posts: 19
Joined: 07 Oct 2016, 06:37
Location: UK

Printscreening with AHK - Freeze the screen!

24 Nov 2016, 07:39

Hello all,

So I'm an ICT Technician at a secondary school. We've recently updated our Smart Boards but the software doesn't come with any function to freeze the screens, which the teachers have used for years. Obviously many of them were upset so I went and created an AHK script for freezing the screen. This code is below, this script does work and will run so long as you're using two monitors and both with 1920 x 1080 resolution. Note that people are very welcome to use and take bits of this code if you'd like. It's fairly simple, it may appear to freeze the screen to the end user but in effect, it print screens and then copies this to a GUI and moves the created GUI window (with invisible borders and taskbars) to the correct location on the other screen to appear as if it's frozen.

While unrelated, if anyone has any points about how to improve this code or any issues with it, please let me know, I'd love to improve it. You're welcome to try it out and break it, tell me what I've done awfully.

The issue I'm having... this script works with all of the teachers PC's (all are running Windows 7 32 bit) with the exception of one (which is a 64 bit machine, if this makes a difference). I think it's a technical issue with the code, particularly the lines where I mention I don't understand it! I've never used DllCall up till now and that part is not my code. So when I use the script on this one PC, it freezes as normal but the created image is missing parts... like if you try to freeze the desktop, the image quality is really bad - the fonts are all blurry and the whole wallpaper is just grey on the GUI. Yet if I just press 'prtscn' on my keyboard manually and copy it to paint, the screenshot is fine. Various applications don't work at all with this script, like even Windows Explorer - the text doesn't copy over but the actual interface does. All this happens only on this one individual PC, every other PC works perfectly.

Basically... why!? Is my code wrong?

Thank you!

Code: Select all

open = 0
SetBatchLines -1

;This section detects whether the monitors are in duplicate or extend. If in duplicate, it forces extend
SysGet, monitorcount, MonitorCount 
if (monitorcount < 2) {
Run C:\Windows\System32\DisplaySwitch.exe /extend
Sleep 2500

;If we've already got a frozen screen window open, kill the existing one before opening another
if (open = 1) { 
Gui, Destroy
open = 0
goto next

;Press printscreen and retrieve the data from it. Also make sure the program knows the window is now open
if (open = 0)
open = 1
if file:=A_LoopFileFullPath

;Set the window up to have no borders and not appear in the taskbar. (Comment these two lines out for debugging)
Gui, Margin, 0, 0
Gui, -Border -SysMenu -Caption -DPIScale +ToolWindow

;Determine which is the primary monitor. Then get data about the other one (the smartboard)
SysGet, primary, MonitorPrimary 
if (primary = 1)
	SysGet, smart, Monitor, 2
	SysGet, smart, Monitor, 1

;Format the picture to fit on the NON primary monitor (The smartboard)
if (smartLeft < 0)  
	Gui,Add,Picture,x-1920 y0 w%A_ScreenWidth% h%A_ScreenHeight%,%file%
	Gui,Add,Picture,x0 y0 w%A_ScreenWidth% h%A_ScreenHeight%,%file%

;Not my code! Unsure about this, something to do with the clipboard!

;Need to display the picture differently depending on whether the smartboard is to the left or right of the primary
;If the smartboard is to the left 
if (smartLeft < 0) 
	Gui,Show, x-3840 y0 w3840 h1080
;If the smartboard is to the right
	Gui, Show, w3840 h1080 x1920 y0

;Finally, maximize the window and then wait for the user to press another button
Gui, maximize

;Ask the question. '4' is the type of message box, this one has a yes and a no in it
MsgBox, 4, Force Duplicate Mode?, Would you like to switch to duplicate mode?
IfMsgBox Yes
	Run C:\Windows\System32\DisplaySwitch.exe /clone

;Whether the user pressed yes or no, kill the window and then wait for further input
Gui, Destroy

;In an emergency or if required, kill the whole script with ctrl-shift-F12
Posts: 27
Joined: 30 Sep 2013, 16:09

Re: Printscreening with AHK - Freeze the screen!

01 Dec 2016, 14:04

I don't know DLL's but its possible that a Windows Theme is causing your issue. Any chance you can set the Windows Theme to Classic or to something the other people are using.

Also its possible that DLL is specific to 32 bit Windows. One of the AHK Gurus will need to reply but its possible you may need to check what bit version people are using and adjust the DLL code from there.

Wish I was able to provide more help.
User avatar
Posts: 177
Joined: 07 Apr 2014, 12:05

Re: Printscreening with AHK - Freeze the screen!

01 Dec 2016, 15:08

here's an interesting post, also along the lines of vahju questioning whether this is a DLL specific to 32 bit Windows. In a nutshell, what if you install the 32 bit version of AutoHotKey_L on the 64 bit system? ... liability/
User avatar
Posts: 1518
Joined: 20 Jul 2014, 10:16
GitHub: Masonjar13
Location: Не Россия

Re: Printscreening with AHK - Freeze the screen!

01 Dec 2016, 15:18

Let's skip that problem all together, shall we?
Requires Gdip_All

Code: Select all

#singleInstance force
#include *i <Lib_1>
#include <Gdip_All>

    msgbox,,Error,Couldn't start GDI+
gui,+hwndghwnd -caption +alwaysontop +toolWindow
gui,add,picture,vmp 0xE

bfs:=Gdip_BitmapFromScreen(0) ; number indicates which screen
guiControl,move,mp,% "x0 y0 w" Gdip_GetImageWidth(bfs) . " h" . Gdip_GetImageHeight(bfs)
gui,show,% "x0 y0 w" . Gdip_GetImageWidth(bfs) . " h" . Gdip_GetImageHeight(bfs)



You'll have to edit it to be multi-screen usable, as I set it up to work for only one. Shouldn't be very difficult, considering you already have bits to do such.
Last edited by Masonjar13 on 01 Dec 2016, 15:23, edited 1 time in total.
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
Posts: 4464
Joined: 17 Jul 2016, 01:02

Re: Printscreening with AHK - Freeze the screen!

01 Dec 2016, 15:20

You might want to clear the clipboard before you send printscreen, and then use Clipwait.

Return to “Ask For Help”

Who is online

Users browsing this forum: AHKStudent, c7aesa7r, davidonabus, Google [Bot], omar bishr and 14 guests