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
#SingleInstance,Force
DetectHiddenWindows,On
open = 0
SetBatchLines -1
F8::
;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
next:
if (open = 0)
{
open = 1
send,^{PrintScreen}
Gui,+hwndhwnd
loop,c:\windows\*.bmp,1,1
if file:=A_LoopFileFullPath
break
;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
else
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%
else
Gui,Add,Picture,x0 y0 w%A_ScreenWidth% h%A_ScreenHeight%,%file%
;Not my code! Unsure about this, something to do with the clipboard!
f:=DllCall("User32\OpenClipboard",int,hwnd)
info:=DllCall("User32\GetClipboardData",Uint,8)
handle:=DllCall("User32\GetClipboardData",Uint,2)
f:=DllCall("User32\CloseClipboard",int,hwnd)
SendMessage,0x172,0,handle,Static1,ahk_id%hwnd%
;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
else
Gui, Show, w3840 h1080 x1920 y0
;Finally, maximize the window and then wait for the user to press another button
Gui, maximize
return
}
F9::
;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
reload
;In an emergency or if required, kill the whole script with ctrl-shift-F12
^+F12::
ExitApp