Trapping ALT+, SHIFT+, or CTRL+PRINT SCREEN, &H80 Key Flag

Article translations Article translations
Article ID: 26485
This article was previously published under Q26485
This article has been archived. It is offered "as is" and will no longer be updated.
Expand all | Collapse all

SUMMARY

Problem:

I am unable to trap the PRINT SCREEN key (on an IBM extended keyboard, such as on an IBM AT) when pressed simultaneously with the ALT, SHIFT, or CTRL key. However, these can be trapped, with the exception of CTRL+PRINT SCREEN, within the QuickBasic editing environment.

These keys can be trapped using GW-Basic Interpreter Version 3.20. The following is a code example:
KEY 15, CHR$(&H04) + CHR$(&H37)
KEY(15) ON
ON KEY(15) GOSUB keytrap
idle: GOTO idle
keytrap:

   PRINT "CONTROL+PRINT SCREEN key sequence trapped"
   RETURN
				
Response: This problem results because the value &H80 is missing from the keyboardflag argument of the KEY statement. You must add this value whenever you trap the PRINT SCREEN key on an extended keyboard. Make sure the Num Lock, Caps Lock, and Scroll Lock keys are all in the off position when you are trapping keys with this method.

The correct method for trapping the key is as follows:
KEY 15, CHR$(&H80 + &H4) + CHR$(&H37)
KEY(15) ON

ON KEY(15) GOSUB keytrapidle

WHILE INKEY$ <> "q"

   x = DOEVENTS()

WEND

END

keytrapidle:

   PRINT "CONTROL+PRINT SCREEN key sequence trapped"
   RETURN
				

Properties

Article ID: 26485 - Last Review: February 28, 2014 - Revision: 1.2
Keywords: 
kbnosurvey kbarchive KB26485

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com