You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
2.6KB

  1. @interface TerminalKeyInput
  2. -(void)upKeyPressed;
  3. -(void)downKeyPressed;
  4. -(void)leftKeyPressed;
  5. -(void)rightKeyPressed;
  6. @property(strong, nonatomic) NSTimer *haTimer;
  7. -(void) haHandleLongPress:(UILongPressGestureRecognizer *) arg1;
  8. @end
  9. %hook TerminalKeyInput
  10. %property(strong, nonatomic) NSTimer *haTimer;
  11. -(id) initWithFrame:(CGRect) arg1 {
  12. id orig = %orig;
  13. UILongPressGestureRecognizer *upLongPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(haHandleLongPress:)];
  14. UILongPressGestureRecognizer *downLongPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(haHandleLongPress:)];
  15. UILongPressGestureRecognizer *leftLongPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(haHandleLongPress:)];
  16. UILongPressGestureRecognizer *rightLongPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(haHandleLongPress:)];
  17. id keyboardToolbar = MSHookIvar<id>(self, "toolbar");
  18. [MSHookIvar<UIButton *>(keyboardToolbar, "upKey") addGestureRecognizer:upLongPress];
  19. [MSHookIvar<UIButton *>(keyboardToolbar, "downKey") addGestureRecognizer:downLongPress];
  20. [MSHookIvar<UIButton *>(keyboardToolbar, "leftKey") addGestureRecognizer:leftLongPress];
  21. [MSHookIvar<UIButton *>(keyboardToolbar, "rightKey") addGestureRecognizer:rightLongPress];
  22. return orig;
  23. }
  24. %new
  25. -(void) haHandleLongPress:(UILongPressGestureRecognizer *) recognizer {
  26. NSString *keyName = [[recognizer view] accessibilityLabel];
  27. if (recognizer.state == UIGestureRecognizerStateBegan){
  28. if (![self haTimer]){
  29. if ([keyName isEqualToString:@"Up"]){
  30. [self setHaTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(upKeyPressed) userInfo:nil repeats:YES]];
  31. } else if ([keyName isEqualToString:@"Down"]){
  32. [self setHaTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(downKeyPressed) userInfo:nil repeats:YES]];
  33. } else if ([keyName isEqualToString:@"Left"]){
  34. [self setHaTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(leftKeyPressed) userInfo:nil repeats:YES]];
  35. } else if ([keyName isEqualToString:@"Right"]){
  36. [self setHaTimer:[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(rightKeyPressed) userInfo:nil repeats:YES]];
  37. }
  38. }
  39. } else if (recognizer.state == UIGestureRecognizerStateEnded){
  40. if ([self haTimer]){
  41. [[self haTimer] invalidate];
  42. [self setHaTimer:nil];
  43. }
  44. }
  45. }
  46. %end
  47. %ctor {
  48. %init(TerminalKeyInput = objc_getClass("NewTerm.TerminalKeyInput"));
  49. }