簡體   English   中英

我們如何使用HID鍵盤按鍵拍攝iphone / ipad設備的屏幕截圖?

[英]How can we take the screenshot of iphone/ipad device using HID keyboard key press?

我想創建一個可以幫助我們使用HID鍵盤按鍵進行屏幕截圖的應用程序,但是我不知道如何檢測HID鍵盤按鍵。請事先幫助我,謝謝

我不知道那個特殊的鍵盤,但是使用此代碼,您可以從應用程序中抓彈。 您可以將此代碼置於按鈕操作中並檢查其是否正常工作,但是關於您的鍵盤我一無所知。

UIGraphicsBeginImageContext(self.window.bounds.size);
[self.window.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData * data = UIImagePNGRepresentation(image);
[data writeToFile:@"foo.png" atomically:YES];

2011年4月更新:對於視網膜顯示,將第一行更改為:

if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
UIGraphicsBeginImageContextWithOptions(self.window.bounds.size, NO, [UIScreen mainScreen].scale);
else
UIGraphicsBeginImageContext(self.window.bounds.size);

您可以使用Keyboard notification

#pragma mark - Keyboard notification
- (void)registerForKeyboardNotifications
{    
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillBeShown:)
                                                 name:UIKeyboardWillShowNotification object:nil];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardWillBeHidden:)
                                                 name:UIKeyboardWillHideNotification object:nil];
}

-(void)keyboardWillBeShown:(NSNotification*)aNotification
{

}
- (void)keyboardWillBeHidden:(NSNotification*)aNotification
{

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM