我想创建一个应用程序来帮助我们使用 HID 键盘按键进行屏幕截图,但我不知道如何检测 HID 键盘按键。请帮助我并提前感谢
问问题
588 次
2 回答
0
i dont know about that special keyboard but using of this code you can take a scree shot from your application. You can put this code in button action and check it's working but about your keyboard i have no idea.
UIGraphicsBeginImageContext(self.window.bounds.size);
[self.window.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData * data = UIImagePNGRepresentation(image);
[data writeToFile:@"foo.png" atomically:YES];
UPDATE April 2011: for retina display, change the first line into this:
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
UIGraphicsBeginImageContextWithOptions(self.window.bounds.size, NO, [UIScreen mainScreen].scale);
else
UIGraphicsBeginImageContext(self.window.bounds.size);
于 2013-02-05T11:55:55.403 回答
0
您可以使用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
{
}
于 2013-02-05T12:33:55.910 回答