Leonardo: Modifier key for Print Screen button

Hello,

I am using Leonardo board for Keyboard and Mouse simulation. Counld you please tell me how can I simulate Print screen button from Leonardo. I checked with list of midifier keys. But I didnt find any key for Print screen.

Could you please tell me Key, Hexadecimal and Decimal value for Print screen key for Leonardo.

Regards,
Swapnil

I don't think that is possible. The print screen and the "windows" keys are special keys that do not behave like all other keys on a keyboard.

Thanks for the reply. Is there any other way to do the same using Leonardo?

I would have thought that they would send some sort of code, I just don't know what it is.

Example of where you might look:

http://www.quadibloc.com/comp/scan.htm

1 Like

In Windows, the virtual key scancode for the Print key is 0x2A. (I have no idea how you'd make use of that within Arduino emulating an HID, but I suppose it's generating scancodes somehow.)

Thanks a lot for reply.

Actually I want to use Prnt screen to take snapshot of application software after few actions done by Keyboard and mouse libraries. So after series of test operation, screenshot will be used for verification point. But while using Leonardo Keyboard libraries, I didnt find how to press and release Prit screen Key.

Could you please tell me how can I use Pring Screen scan code Ox2A (as mentioned above by PeterH) while using Leonardo Keyboard libraries?? How can I send parameter in Keyboard.press() and Keyboard.release() for Print screen button.

Sorry for late reply, I was on leave.

I'm not sure it is 0x2A but this is the general idea for pressing and releasing:

                Keyboard.press (KEY_LEFT_ARROW);
                Keyboard.releaseAll();

I don't think the scan code will necessarily be the USB code. You could try 0x46 which I got from the page I linked above. But no guarantees.

hi Nick, I tried with 0x46 by Keyboard.press(70) and Keyboard.releaseAll() but it doesnt work. Any other USB code for Print Screen button that would make it?
Is this limitation of Leonardo Keyboard libraries? Or can we create external libraries to do Print Screen press-release operation?

Perhaps post your code?

Here is my code:

Where I need to implement Print screen to validate the operation.

/*
 Code is to test one module of S/w application. Here if char '1' is received from Serial1 of Leonardo, 
 then by using Keyboard library it will press Alt+f and then 'o' button to open the window.
 As window is open. Test need to validate the open window by taking screen shot of window. 
 To take screen shot of window, print screen button need to press and release.
 */
void setup() { // initialize
  Serial1.begin(9600);
  Serial.begin(9600);
  while (! Serial1);
  while (! Serial);

  Mouse.begin();  
  Keyboard.begin();
}

void loop() {
  
  if (Serial1.available() > 0) {
    char inChar = Serial1.read();
    
    switch (inChar) {   
        case '1':
        delay(1000); 
        Keyboard.press(KEY_LEFT_ALT);
        delay(100);
        Keyboard.press('f');
        delay(100);
        Keyboard.releaseAll();
        delay(100);
        Keyboard.press('o');
        delay(100);
        Keyboard.releaseAll();
        delay(500);
        //Here I want to do validation for open window. I need to take screen shot of open window by KeyBoard library.
        //If print screen would be implemented then code would be as below:
        
//        Keyboard.press(KEY_PRNT_SCRN); //Yet Did not find modifier key for Print screen.
//        delay(100);
//        Keyboard.releaseAll();
//        //open microsoft paint to store screen shot 
//        Keyboard.press(KEY_LEFT_GUI) //window key
//        Keyboard.press('r')
//        delay(100);
//        Keyboard.releaseAll();
//        
//        Keyboard.print("mspaint");
//        delay(100);
//        Keyboard.press(KEY_RETURN)
//        delay(100);
//        Keyboard.releaseAll();
//        //Then Paste the screen shot by Cntrl+V and save the image.
        
        break;
        
        default:
        Serial.print("Default Case");
        
        
    } //switch end

  } //if end

}//void loop End
//        Keyboard.press(KEY_PRNT_SCRN); //Yet Did not find modifier key for Print screen.
//        delay(100);
//        Keyboard.releaseAll();

The code that actually implements KEY_PRNT_SCRN.

"KEY_PRNT_SCRN" modifier key is not available for Keyboard.press(); function. Please check link: http://arduino.cc/en/Reference/KeyboardModifiers

I put line of code to define the purpose of print screen. If I verify code, it throws compile error as "error: 'KEY_PRNT_SCRN' was not declared in this scope"

I'm still not seeing code, that compiles, that doesn't work.

Look:

Read this before posting a programming question

Hi nick, below code will throw error on verify:

Keyboard.press(KEY_PRNT_SCRN); //Yet Did not find modifier key for Print screen.
        delay(100);
        Keyboard.releaseAll();

it throws compile error as "error: 'KEY_PRNT_SCRN' was not declared in this scope"

As KEY_PRNT_SCRN is not supported modifier key available in list:
http://arduino.cc/en/Reference/KeyboardModifiers

swap_philips:
hi Nick, I tried with 0x46 by Keyboard.press(70) and Keyboard.releaseAll() but it doesnt work.

You said "it doesn't work" not "it doesn't compile".

Look, this is about 10 posts later. Can you please post the code, which you said doesn't work. I don't want to see attempts to get it to compile.

Here is code: Please try to compile the below code:

void setup() { // initialize
  Serial1.begin(9600);
  Serial.begin(9600);
  while (! Serial1);
  while (! Serial);

  Mouse.begin();  
  Keyboard.begin();
}

void loop() {
  
  if (Serial1.available() > 0) {
    char inChar = Serial1.read();
    
    switch (inChar) {   
        case '1':
        delay(1000); 
        Keyboard.press(KEY_LEFT_ALT);
        delay(100);
        Keyboard.press('f');
        delay(100);
        Keyboard.releaseAll();
        delay(100);
        Keyboard.press('o');
        delay(100);
        Keyboard.releaseAll();
        delay(500);
        //Here I want to do validation for open window. I need to take screen shot of open window by KeyBoard library.
        //If print screen would be implemented then code would be as below:
        
        Keyboard.press(KEY_PRNT_SCRN); //Yet Did not find modifier key for Print screen.
        delay(100);
        Keyboard.releaseAll();
        //open microsoft paint to store screen shot 
        Keyboard.press(KEY_LEFT_GUI) //window key
        Keyboard.press('r')
        delay(100);
        Keyboard.releaseAll();
        
        Keyboard.print("mspaint");
        delay(100);
        Keyboard.press(KEY_RETURN)
        delay(100);
        Keyboard.releaseAll();
        //Then Paste the screen shot by Cntrl+V and save the image.
        
        break;
        
        default:
        Serial.print("Default Case");
        
        
    } //switch end

  } //if end

}//void loop End

I have the same problem, after google and found no solution.
So I think I should share my current findings to all.

After reading USB HID specification and Arduino’s USBAPI.h/HID.cpp, I found this maybe work:

#define KEY_PRNT_SCRN 206

In HID spec, F12 key id is 69, PrintScreen is 70.
But in arduino’s defines, F12 is 205.

Finally I found there is translate in HID.cpp:

size_t Keyboard_::release(uint8_t k)
{
uint8_t i;
if (k >= 136) { // it’s a non-printing key (not a modifier)
** k = k - 136;**
} else if (k >= 128) { // it’s a modifier key
_keyReport.modifiers &= ~(1<<(k-128));
k = 0;
} else { // it’s a printing key
k = pgm_read_byte(_asciimap + k);

You can see, F12 is 205-136=69, so if you want send 70, try 206

Arduino’s API try to compitable with ASCII input, and do some convertion.