Detect / receive notification if shift key (modifier key) is pressed in uitextview

I am trying to find out if there is a way to detect if the shift key is pressed or if any notification is sent when the shift key is pressed in UIKeyboard

 - (BOOL) textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)string 

It is not called to press the shift key, because it is a modifier key.

+4
source share
1 answer

I don’t know if you need to know this in combination with other text or to detect only a single click, but here is my solution to detect the first:

in my case it is only one character inside:

 - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)inText 

this converts the uppercase text to lowercase and sets the value to shiftPressed (ignored if the text is not alphabetic text)

 //Shift Detection BOOL shiftPressed = NO; //Detect non letter characters NSCharacterSet *letterCharacterSet = [NSCharacterSet letterCharacterSet]; NSString *trimmedText = [text stringByTrimmingCharactersInSet:letterCharacterSet]; if ([text length] == 1) { if (![trimmedText length]) { NSString *upperCaseString = [text uppercaseString]; if ([upperCaseString isEqualToString:text]) { NSString *lowerCaseString = [text lowercaseString]; text = lowerCaseString; shiftPressed = YES; } } } 
+2
source

Source: https://habr.com/ru/post/1346845/


All Articles