Article ID: 59133 - View products that this article applies to.
This article was previously published under Q59133
You can detect (trap) the PRINT SCREEN (or SHIFT+PRINT SCREEN, or PRT SCR, and so on) key using the ON KEY GOSUB statement. This technique does not work under Microsoft Windows, and may not work reliably on all computers (it depends upon the type of ROM BIOS).
Although Basic can detect the key press with the ON KEY GOSUB statement, the PRINT SCREEN action is controlled through the ROM BIOS interrupt table, and cannot be disabled directly with Basic. To disable the print screen utility, the interrupt vector must be remapped with a C or assembly routine.
Here is the syntax of the KEY statement, where n=15-25 can be user-defined key combinations to trap:
The following chart shows the keyboard flags and scan codes for PRINT SCREEN and SHIFT+PRINT SCREEN for standard and extended keyboards:
Note: The keyboard flags are affected by CAPS LOCK and NUM LOCK. The above values assume that CAPS LOCK and NUM LOCK are off. Add &H40 to the keyboard flag for CAPS LOCK, and add &H20 for NUM LOCK.
Standard Extended -------- -------- Keyboard flag for: No SHIFT &H00 &H80 LEFT SHIFT &H02 &H82 RIGHT SHIFT &H01 &H81 Scan code for: PRINT SCREEN &H37 &H2A
Code ExampleThe following code example detects each of the PRINT SCREEN and SHIFT+PRINT SCREEN combinations listed above:
Article ID: 59133 - Last Review: August 16, 2005 - Revision: 2.1
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.