Getting Input from the Touch Screen

Discussion in 'iOS Development' started by ichaelmay8, Mar 15, 2008.

  1. ichaelmay8

    ichaelmay8 New Member

    Joined:
    Dec 31, 2007
    Messages:
    17
    Likes Received:
    0
    Getting Input from the Touch Screen: help?

    I'm new to objective-c and cocoa. However, I've got some experience with C.

    I've been digging around in the source code of some applications, and I haven't been able to figure out how input is accomplished. Can someone please help me out?
  2. Mantu

    Mantu New Member

    Joined:
    Dec 26, 2007
    Messages:
    46
    Likes Received:
    14
    Device:
    iPod touch
    If I understood you right this is what you need:

    Code:
    -(void)mouseDown:(struct __GSEvent *)event
    {
    	//Do something here
    	[super mouseUp:event];
    }
    
  3. Yongobongo

    Yongobongo New Member

    Joined:
    Dec 28, 2007
    Messages:
    121
    Likes Received:
    1
    Device:
    iPhone 4 (Black)
    How would I get the X and Y values of the touch?
  4. Mantu

    Mantu New Member

    Joined:
    Dec 26, 2007
    Messages:
    46
    Likes Received:
    14
    Device:
    iPod touch
    If I remember right this is the way:

    Code:
    -(void)mouseDown:(struct __GSEvent *)event
    {
    	CGPoint point;
    
            point = GSEventGetLocationInWindow(event);
            point = [self convertPoint:point fromView:nil];
    
    	[super mouseUp:event];
    }
    
  5. ichaelmay8

    ichaelmay8 New Member

    Joined:
    Dec 31, 2007
    Messages:
    17
    Likes Received:
    0
    Thanks for your help.

    For getting the points, i've been using this:

    Code:
    -(void)mouseDown:(struct __GSEvent *)event
    {
        int tap_x, tap_y;
    
        tap_x = CGRectGetMinX(GSEventGetLocationInWindow(event));
        tap_y = CGRectGetMaxY(GSEventGetLocationInWindow(event));
    
       [super mouseUp:event];
    }
    
    Your way is probably better though.
  6. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    A if you needed one more example. Here's the code I used in PocketTouch.

    Code:
    -(void)mouseDown:(struct __GSEvent *)event;
    {
    	userDidSwipe = FALSE;
    	down = GSEventGetLocationInWindow(event);
    	NSLog(@"Clicked at X:%f Y:%f\n", down.x, down.y);
    	
    	NSTimer *clickTimer = [NSTimer scheduledTimerWithTimeInterval: 1.5 target: self selector: @selector(changeView:) userInfo: nil repeats: NO];
    }	
    A CGPoint, in this case "down," is an object. As with all objects, you can get its public variables by using this syntax: object.variable. Meaning, in this case that the mouse down occurred at down.x and down.y.


    EDIT: Don't worry, I invalidate that timer later on, after it fires, lol.
  7. lgchicken

    lgchicken New Member

    Joined:
    Apr 12, 2008
    Messages:
    80
    Likes Received:
    1
    sorry for ressurecting an old thread, but ive tried all of your code above
    ann i keep getting

    PHP:
    /usr/local/bin/arm-apple-darwin-ldUndefined symbols:
    _GSEventGetLocationInWindow
    collect2
    ld returned 1 exit status
    what does this mean?

    i added
    PHP:
    #import  <GraphicsServices/GraphicsServices.h>
    because thats where the function is?

    this happens when i try in an application or a view btw.
    any help?
  8. Mantu

    Mantu New Member

    Joined:
    Dec 26, 2007
    Messages:
    46
    Likes Received:
    14
    Device:
    iPod touch
    Add this to makefile: -framework GraphicsServices
  9. lgchicken

    lgchicken New Member

    Joined:
    Apr 12, 2008
    Messages:
    80
    Likes Received:
    1
    ahh thankyou very much
    (blame SkylarEC's makefile)
    naa, just joking,
    cheers

    Please Register or Log in to view images

Share This Page