Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7039385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:47:31+00:00 2026-05-28T01:47:31+00:00

When I subclass a widget and define a keyDown method, and then in InterfaceBuilder

  • 0

When I subclass a widget and define a keyDown method, and then in InterfaceBuilder assign the class of a widget to be the class I defined with the keyDown method, it seems to work fine.

However, if I do it complete programmatically as illustrated in the simple script below, the keyDown method never gets called. Why is this?

Is there something being set up by XCode that is causing the app to listen for events that gets done behind the scenes? What is it, and how do I do it here? Please point me in the right direction.

I’m gonna go read through the apple docs again and try to figure out if there is an event handler registration going on that XCode is setting for me. However, if you know what it is, please let me know.

Thanks!

framework 'Cocoa'

class MyView < NSView
  def acceptsFirstResponder
    true
  end

  def keyDown(event)
    puts "key down MyView"
  end
end

class MyWindow < NSWindow
  def acceptsFirstResponder
    true
  end

  def keyDown(event)
    puts "key down in MyWin"
  end
end

class MyApp < NSApplication
  def acceptsFirstResponder
    true
  end

  def keyDown(event)
    puts "key down in MyApp"
  end
end

application = MyApp.sharedApplication

# create the window
frame  = [0.0, 0.0, 300, 200]
mask = NSTitledWindowMask | NSClosableWindowMask
window = MyWindow.alloc.initWithContentRect(frame,
          styleMask:mask,
          backing:NSBackingStoreBuffered,
          defer:false)

# assign a content view instance
content_view = MyView.alloc.initWithFrame(frame)
window.contentView = content_view

window.makeFirstResponder(window)

# show the window
window.display
window.makeKeyAndOrderFront(nil)

application.run
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:47:32+00:00Added an answer on May 28, 2026 at 1:47 am

    You can do it without an application bundle and plist, but you need to start the app like so:

    app = MyApp.sharedApplication
    app.activationPolicy = NSApplicationActivationPolicyRegular
    app.activateIgnoringOtherApps(true)
    app.run
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If subclass in objective-c wants to override a super class's method, does it have
New class is a subclass of the original object It needs to be php4
I have a subclass with an over-ridden method that I know always returns a
If I derive my class from QObject (or a subclass), the Qt documentation says
The usual way to use Qt widgets from Python seems to be to subclass
I'm trying to set up a parent class that extends a subclass, but whenever
A bit of help please, consider the bit of code below. public class Widget
I created a widget that is a subclass of Composite and has a com.extjs.gxt.ui.client.widget.Viewport
I use widget=forms.CheckboxSelectMultiple in a ModelForm subclass to change the field display to checkboxes.
My View doesn't use an XML layout, I just reference a View subclass defined

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.