VMKeyboardView.m 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //
  2. // Copyright © 2019 osy. All rights reserved.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. #import "VMKeyboardView.h"
  17. #import "VMKeyboardMap.h"
  18. @interface VMKeyboardView ()
  19. @property (nullable, nonatomic) VMKeyboardMap *keyboardMap;
  20. @end
  21. @implementation VMKeyboardView
  22. - (UIKeyboardType)keyboardType {
  23. return UIKeyboardTypeASCIICapable;
  24. }
  25. - (UITextAutocapitalizationType)autocapitalizationType {
  26. return UITextAutocapitalizationTypeNone;
  27. }
  28. - (UITextAutocorrectionType)autocorrectionType {
  29. return UITextAutocorrectionTypeNo;
  30. }
  31. - (UITextSpellCheckingType)spellCheckingType {
  32. return UITextSpellCheckingTypeNo;
  33. }
  34. - (UITextSmartQuotesType)smartQuotesType {
  35. return UITextSmartQuotesTypeNo;
  36. }
  37. - (UITextSmartDashesType)smartDashesType {
  38. return UITextSmartDashesTypeNo;
  39. }
  40. - (UITextSmartInsertDeleteType)smartInsertDeleteType {
  41. return UITextSmartInsertDeleteTypeNo;
  42. }
  43. - (BOOL)hasText {
  44. return YES;
  45. }
  46. - (void)deleteBackward {
  47. [self.delegate keyboardView:self didPressKeyDown:0x0E];
  48. [NSThread sleepForTimeInterval:0.05f];
  49. [self.delegate keyboardView:self didPressKeyUp:0x0E];
  50. }
  51. - (void)insertText:(nonnull NSString *)text {
  52. if (!self.keyboardMap) {
  53. self.keyboardMap = [[VMKeyboardMap alloc] init];
  54. }
  55. [self.keyboardMap mapText:text toKeyUp:^(NSInteger scanCode) {
  56. [self.delegate keyboardView:self didPressKeyUp:(int)scanCode];
  57. } keyDown:^(NSInteger scanCode) {
  58. [self.delegate keyboardView:self didPressKeyDown:(int)scanCode];
  59. } completion:^(){}];
  60. }
  61. - (BOOL)canBecomeFirstResponder {
  62. return YES;
  63. }
  64. @end