Posts: 1,270
Threads: 118
Joined: Apr 2022
Reputation:
100
Does anyone have any ideas on how a QB64PE program can disable the print screen function when running?
Ideally I would like to be able to hook the keyboard's PRINT SCREEN key to intercept keypresses while at the same time disabling the operating system from grabbing a screen shot. However, disabling the operating system's ability to perform screen shots while the program is running would be just as useful.
Any thoughts, ideas?
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Posts: 1,270
Threads: 118
Joined: Apr 2022
Reputation:
100
One method I came up with was using _CLIPBOARDIMAGE to "poison the well" so to speak. Any program I write would need to write garbage to the clipboard periodically like the example below
Code: (Select All) 'Poison the well
image = _NEWIMAGE(100, 100, 32)
_DEST image
PRINT
PRINT
PRINT " NO!"
_DEST 0
DO
SLEEP 1
_CLIPBOARDIMAGE = image
LOOP UNTIL INKEY$ <> ""
SYSTEM
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Posts: 1,581
Threads: 59
Joined: Jul 2022
Reputation:
52
12-15-2023, 10:08 PM
(This post was last modified: 12-15-2023, 10:11 PM by mnrvovrfc.
Edit Reason: Clarification, typing mistakes
)
(12-15-2023, 08:01 PM)TerryRitchie Wrote: However, disabling the operating system's ability to perform screen shots while the program is running would be just as useful.
Many users expect to record entire videos of what they are doing in an operating system desktop session. With the big talk about the whole of Linux moving from "X-dot-org" to Wayland, it might become impossible to do what you are requesting. However, under Wayland it's already tough enough to record desktop sessions into video.
Some people especially on Linux would not touch a program that disables [PRT SC] or any other key, would consider it spyware. If it comes directly from you this could affect your reputation as educator. An user could press the key without thinking much about it, or because he/she wants to show off to his/her friends on Facebook or wherever else online. If the program doesn't respond to some "system" keypress there better be a good reason why. But this might be the minority of the population using Windows anyway.
It's bothersome that [CTRL][ALT][DEL] on Linux with GNOME desktop only opens the "shutdown" dialog. It does not reboot the computer, and it does not bring a dialog asking the user how to end the current desktop session.
I would like to get a reason from the devs of AutoHotKey, besides "It's too hard!" why it has never been ported to Linux. There is an old version of AutoIt that somebody sort of fixed so it works on Linux reasonably, but it relies way too much on Python and it would probably be forbidden in Wayland session.
Posts: 73
Threads: 3
Joined: Apr 2022
Reputation:
14
(12-15-2023, 09:11 PM)TerryRitchie Wrote: One method I came up with was using _CLIPBOARDIMAGE to "poison the well" so to speak. Any program I write would need to write garbage to the clipboard periodically like the example below
Code: (Select All) 'Poison the well
image = _NEWIMAGE(100, 100, 32)
_DEST image
PRINT
PRINT
PRINT " NO!"
_DEST 0
DO
SLEEP 1
_CLIPBOARDIMAGE = image
LOOP UNTIL INKEY$ <> ""
SYSTEM
This could also work under Windows.
Code: (Select All)
SCREEN _NEWIMAGE(800, 600, 32)
DO
CLS
COLOR _RGB32(177, 177, 177)
PRINT "Monitoring clipboard..."
IF img& < -1 THEN _FREEIMAGE img&
img& = _CLIPBOARDIMAGE
IF img& < -1 THEN
Shell "cmd /c echo off | clip"
END IF
_DISPLAY
_LIMIT 10
LOOP
But starting with Win 10, the clipboard can store more than one page.
Posts: 2,700
Threads: 328
Joined: Apr 2022
Reputation:
219
Posts: 2,700
Threads: 328
Joined: Apr 2022
Reputation:
219
Code: (Select All) //////////////////
// When window is activated/deactivated, disable/enable Alt-PrintScreen.
// (IDHOT_SNAPWINDOW)
//
void CMainFrame::OnActivate(UINT nState, CWnd* pWndOther,
BOOL bMinimized)
{
CFrameWnd::OnActivate(nState, pWndOther, bMinimized);
if (nState)
RegisterHotKey(m_hWnd, IDHOT_SNAPWINDOW, MOD_ALT, VK_SNAPSHOT);
else
UnregisterHotKey(m_hWnd, IDHOT_SNAPWINDOW);
}
I think right there is what would be really relevant for you, but read the article itself, also.
Posts: 1,270
Threads: 118
Joined: Apr 2022
Reputation:
100
(12-15-2023, 10:28 PM)Steffan-68 Wrote: But starting with Win 10, the clipboard can store more than one page. Yeah, I was wondering about that issue too.
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Posts: 1,270
Threads: 118
Joined: Apr 2022
Reputation:
100
(12-15-2023, 10:36 PM)SMcNeill Wrote: Code: (Select All) //////////////////
// When window is activated/deactivated, disable/enable Alt-PrintScreen.
// (IDHOT_SNAPWINDOW)
//
void CMainFrame::OnActivate(UINT nState, CWnd* pWndOther,
BOOL bMinimized)
{
CFrameWnd::OnActivate(nState, pWndOther, bMinimized);
if (nState)
RegisterHotKey(m_hWnd, IDHOT_SNAPWINDOW, MOD_ALT, VK_SNAPSHOT);
else
UnregisterHotKey(m_hWnd, IDHOT_SNAPWINDOW);
}
I think right there is what would be really relevant for you, but read the article itself, also. Thanks for the info Steve, I'll take a look.
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Posts: 2,700
Threads: 328
Joined: Apr 2022
Reputation:
219
Finally having a little time to sit down and relax -- and try not to fall asleep with my stomach bursting with Christmas Eve Lunch -- I think I put the pieces together here for what you're looking for:
Code: (Select All)
'BOOL UnregisterHotKey(
' [in, optional] HWND hWnd,
' [in] int id
');
'BOOL RegisterHotKey(
' [in, optional] HWND hWnd,
' [in] int id,
' [in] UINT fsModifiers,
' [in] UINT vk
');
Const Alt = 1
Const VK_Snapshot = &H2C
Declare Dynamic Library "user32"
Function RegisterHotKey%% (ByVal WindowHandle As _Offset, Byval id As Long, Byval keyModifiers As _Unsigned Long, Byval keyValue As _Unsigned Long)
Function UnregisterHotKey%% (ByVal WindowHandle As _Offset, Byval id As Long)
End Declare
Dim Internal_Key_Name As Long
Dim WH As _Offset: WH = _WindowHandle
result = RegisterHotKey(0, 1, Alt, VK_Snapshot) '0 is null, so defaults to this program. 1 is the id value that we assign to... I dunno! It just works! LOL.
If result Then
Print "Alt-Printscreen is enabled in this program."
Print "Attempting to disable it..."
result = UnregisterHotKey(0, 1)
If result Then
Print "We should now have disabled Alt-Printscreen in this application"
Else
Print "No luck. Sorry dude. Try again later!"
End If
Else
Print "No can do! Either alt-printscreen is already broken or assigned elsewhere, or else we just goofed up somewhere!"
Print "Sorry dude. Try again later!"
End If
Posts: 2,700
Threads: 328
Joined: Apr 2022
Reputation:
219
(That 1, I think is some sort of internal register that we first configure with the RegisterHotKey so that it represents Alt+Printscreen. It's why we use that same value with unregister so we unregister that combo of keystrokes from our program, with that singular value.)
|