[PB 3.94] Getting the print screen button in PB

Just starting out? Need help? Post your questions and find answers here.
theteapot
User
User
Posts: 37
Joined: Fri Sep 09, 2005 7:46 am

[PB 3.94] Getting the print screen button in PB

Post by theteapot »

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
Using PB 3.94 demo AND PROUD OF IT!!

*Goes back to little hole*
User avatar
Shardik
Addict
Addict
Posts: 2075
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Post by Shardik »

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):

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
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> I would have thought that the constant #VK_PRINT would be correct

It's #VK_SNAPSHOT.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
Shardik
Addict
Addict
Posts: 2075
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Post by Shardik »

Thank you, PB. You are right. I must have been blind for overlooking this constant :oops:

theteapot should change the line

Code: Select all

If EventwParam() = 44
against

Code: Select all

If EventwParam() = #VK_SNAPSHOT
in my example.
USCode
Addict
Addict
Posts: 924
Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle

Post by USCode »

Should the constant #PB_Key_PrintScreen be declared by Fred?
If so, please make the request in the Wishlist forum.
The more we can abstract from the native OS API the better!
theteapot
User
User
Posts: 37
Joined: Fri Sep 09, 2005 7:46 am

Post by theteapot »

Sorry, I may not have made myself clear enough. I wanted to see if the user had pressed that key on a screen.

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*
User avatar
Shardik
Addict
Addict
Posts: 2075
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Post by Shardik »

Replace #PB_Key_PrintScreen by the decimal value 183 and your code example works as wanted...
theteapot
User
User
Posts: 37
Joined: Fri Sep 09, 2005 7:46 am

Post by theteapot »

Thanks!

Where did you find it by the way?
Using PB 3.94 demo AND PROUD OF IT!!

*Goes back to little hole*
User avatar
Shardik
Addict
Addict
Posts: 2075
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Post by Shardik »

Where did you find it by the way?
I modified the demo program from PureBASIC help for the KeyboardInkey() command to display the keyboard scancode for each pressed key in screen mode:

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
To display the scan code for the Print key you perhaps have to keep the Print key pressed a longer time...
Post Reply