Iphone development: Keyboard Events

Source: Internet
Author: User





UIKIT_EXTERN NSString * const UITextInputCurrentInputModeDidChangeNotification _ OSX_AVAILABLE_STARTING (_ MAC_NA ,__ IPHONE_4_2 );
This notification is available.

[[Nsicationcenter center defacenter center] addObserver: self selector: @ selector (changeMode :) name: @ "UITextInputCurrentInputModeDidChangeNotification" object: nil];
Then implement the above method:
-(Void) changeMode :( NSNotification *) notification {
NSLog (@ "% @", [[UITextInputMode currentInputMode] primaryLanguage]);
}
In this way, you can get the value.
The following is the LOG result:
14:32:48. 565 UIFont [2447: 207] zh-Hans // Simplified Chinese pinyin
14:32:50. 784 UIFont [2447: 207] en-US // english
14:32:51. 344 UIFont [2447: 207] zh-Hans // simplified handwriting
14:32:51. 807 UIFont [2447: 207] zh-Hans // simplified strokes
14:32:53. 271 UIFont [2447: 207] zh-Hant // traditional handwriting
14:32:54. 062 UIFont [2447: 207] zh-Hant // traditional cangjie
14:32:54. 822 UIFont [2447: 207] zh-Hant // traditional strokes
LOG shows the language in which the user is input. However, this is sufficient for most current applications.
Direct retrieval:
[[UITextInputMode currentInputMode] primaryLanguage];

Actually, it returns a UIKeyboardInputMode class. This is a private API and not only the primaryLanguage attribute.


@ Interface UIKeyboardInputMode: UITextInputMode
{
NSString * primaryLanguage;
NSString * identifier;
NSString * softwareLayout;
NSString * hardwareLayout;
}

+ (Id) keyboardInputModeWithIdentifier :( id) arg1;
+ (Id) hardwareLayoutFromIdentifier :( id) arg1;
+ (Id) softwareLayoutFromIdentifier :( id) arg1;
+ (Id) canonicalLanguageIdentifierFromIdentifier :( id) arg1;
@ Property (retain, nonatomic) NSString * hardwareLayout; // @ synthesize hardwareLayout;
@ Property (retain, nonatomic) NSString * softwareLayout; // @ synthesize softwareLayout;
@ Property (retain, nonatomic) NSString * identifier; // @ synthesize identifier;
@ Property (retain, nonatomic) NSString * primaryLanguage; // @ synthesize primaryLanguage;
-(Void) dealloc;
-(Id) initWithIdentifier :( id) arg1;

@ End

@ Property (retain, nonatomic) NSString * hardwareLayout; // @ synthesize hardwareLayout;
@ Property (retain, nonatomic) NSString * softwareLayout; // @ synthesize softwareLayout;
@ Property (retain, nonatomic) NSString * identifier; // @ synthesize identifier;
@ Property (retain, nonatomic) NSString * primaryLanguage; // @ synthesize primaryLanguage;
Determination of these attributes

NSLog (@ "% @", [(UIKeyboardInputMode *) [UITextInputMode currentInputMode] identifier]);
It can be determined by identifier. Each type is different. You can log it and see it.

According to indentifier

UITextInputMode * inputMode = [UITextInputMode currentInputMode];
NSString * indentifier = [inputMode into mselector: NSSelectorFromString (@ "identifier")];
NSLog (@ "% @", indentifier );
// Simplified stroke zh_Hans-Wubihua @ sw = Wubihua; hw = US
// Simplified handwritten zh_Hans-HWR @ sw = HWR
// Simplified Pinyin zh_Hans-Pinyin @ sw = Pinyin; hw = US
// En_US @ hw = US; sw = QWERTY

 


From cloud huaikong-abel

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.