[PB 3.94] Getting the print screen button in PB
[PB 3.94] Getting the print screen button in PB
How can I find out if the user has pressed the print screen button on my screen?
There is no #PB_Key_PrintScreen constant! Is there a numeric value which I can use?
The key does get captured with #PB_Key_All.
Thanks, TheTeapot
There is no #PB_Key_PrintScreen constant! Is there a numeric value which I can use?
The key does get captured with #PB_Key_All.
Thanks, TheTeapot
Using PB 3.94 demo AND PROUD OF IT!!
*Goes back to little hole*
*Goes back to little hole*
You can detect the Print Screen button with the value 44 (decimal). I would have thought that the constant #VK_PRINT would be correct, but unfortunately it has the value 42...
Here is a short demo code for PB 3.94 (for PB 4 you have to change the OpenWindow statement):
Here is a short demo code for PB 3.94 (for PB 4 you have to change the OpenWindow statement):
Code: Select all
OpenWindow(1, 0, 0, 200, 15, #PB_Window_ScreenCentered | #PB_Window_SystemMenu, "PrintKey Detection")
Repeat
Select WaitWindowEvent()
Case #WM_KEYUP
If EventwParam() = 44
MessageRequester("Info", "You have pressed the Print key...")
EndIf
Case #PB_Event_CloseWindow
End
EndSelect
ForEver
Thank you, PB. You are right. I must have been blind for overlooking this constant
theteapot should change the line
against
in my example.
theteapot should change the line
Code: Select all
If EventwParam() = 44Code: Select all
If EventwParam() = #VK_SNAPSHOTSorry, I may not have made myself clear enough. I wanted to see if the user had pressed that key on a screen.
For example:
For example:
Code: Select all
InitSprite()
InitKeyboard()
OpenScreen(1024,768,32,"")
Repeat
ExamineKeyboard()
Delay(20)
Until KeyboardReleased(#PB_Key_PrintScreen) ; This will never evalutate to true, because it doesn't exist!
CloseScreen()Using PB 3.94 demo AND PROUD OF IT!!
*Goes back to little hole*
*Goes back to little hole*
I modified the demo program from PureBASIC help for the KeyboardInkey() command to display the keyboard scancode for each pressed key in screen mode:Where did you find it by the way?
Code: Select all
If InitSprite() And InitKeyboard() And OpenScreen(1024, 768, 32, "")
Repeat
FlipBuffers()
ClearScreen(0, 0, 0)
ExamineKeyboard()
For i = 1 To 255
If KeyboardReleased(i) = 1
KeyReleased = i
Break
EndIf
Next i
If StartDrawing(ScreenOutput())
DrawingMode(1)
FrontColor(128, 255, 0)
Locate(300, 360) : DrawText("Please press a key (Terminate program with <ESC>):")
If KeyReleased = 0
Locate(430, 420) : DrawText("Key code:")
Else
Locate(430, 420) : DrawText("Key code: " + Str(KeyReleased))
EndIf
StopDrawing()
EndIf
Until KeyboardPushed(#PB_Key_Escape)
EndIf

