0
votes

I am using NSScrollView to display a very long NSView, which width is more than 72000 pixels. It scrolls well when I drag the knob, and it also responds well to scrollRectToVisible method.

And then, I am using a timer to update the NSScrollView from left to right. All things run well except when I press the space key. When the space key is pressed, the scroll view will stopped for a little while. When I hold the space key down, the scroll view will flash right and left.

I wonder how I can disable the space key for the nsscroll view, because I don't want any space key interactions

I turned on the NSTraceEvent, and found out the following logs:

2011-12-22 12:36:51.563 CIVideoDemoGL[255:a0f] Received event: KeyDown at: 131.0,880.0 time: 262523518000 flags: 0x100 win: 0 ctxt: af37 data: 1,252,32,49,32

2011-12-22 12:36:51.563 CIVideoDemoGL[255:a0f] In Application: NSEvent: type=KeyDown loc=(0,944) time=262.5 flags=0x100 win=0x0 winNum=47 ctxt=0xaf37 chars=" " unmodchars=" " repeat=1 keyCode=49

2011-12-22 12:36:51.563 CIVideoDemoGL[255:a0f] In Window: NSEvent: type=KeyDown loc=(0,944) time=262.5 flags=0x100 win=0x0 winNum=47 ctxt=0xaf37 chars=" " unmodchars=" " repeat=1 keyCode=49

2011-12-22 12:36:51.564 CIVideoDemoGL[255:a0f] timeout = 62767682588.435905 seconds, mask = ffffffff, dequeue = 1, mode = kCFRunLoopDefaultMode

What should I do to ignore the space key down event for nsscrollview?

1

1 Answers

0
votes

You should subclass NSScrollView, override -keyDown: and in your implementation ignore spaces.

However, I think it's generally unwise to use such a large NSView. Instead, you should use a smaller NSView and only draw the visible part of the content you're displaying. You will need to implement your own scrolling using NSScroller objects but this will give you much better performance than a huge NSView.