tags:

views:

87

answers:

1

Hi , I'm a newbie,

I'm trying to learn objective-c.I have developed a small application which accepts user input and saves it in sqllite. Curently my application supports only english keyboard layout. I have put radiobutton with options English and Danish. On option select the keyboard layout should change to desired on and accept the input.

Can anybody help be outwith this.

Thank in advance.

A: 

Are you saving raw key codes? As if not, the layout is completely uninteresting to you, Cocoa will convert any combination of key codes into Unicode characters that you can save. That way your code will work with whatever exotic keyboard layout the user might have (e.g. Dvorak or Colemak are also English keyboard layouts).

However, to answer your questions, yes, you can get notifications whenever the layout changes. For 10.5 or 10.6 use Text Input Services. The notification is named kTISNotifySelectedKeyboardInputSourceChanged and is sent whenever the user picks another keyboard layout (the other notification is kTISNotifyEnabledKeyboardInputSourcesChanged, this is one is sent whenever the user adds or removes layouts from the list of selectable layouts). It's a normal CF distributed notification that you can receive in your application like all CF distributed notifications. See documentation for CFNotificationCenter.

Maybe those notifications are also receivable as NSNotifications via NSNotificationCenter, but that is not documented anywhere as far as I can see. Using CF (Core Foundation) API in a Cocoa application is no problem, though. You can easily wrap all necessary code into a nice Obj-C object.

Mecki
Hi Mecki,My made the necessary changes and run it in development environment it allows me to enter in Danish but when i package it and install the whole appln. it only accepts english keyboad layout entry. Please help me to figure it out.
frederic
@frederic: I'm still not sure what you are actually trying to do. I'm not sure why you even care for the keyboard layout in your application at all. The user selects the keyboard layout via a shortcut or via the keyboard layout flag menu item. Why does the user have to select the keyboard layout in your application instead of using the standard way for doing so that MacOSX offers? Please update your question accordingly. If I'd understand what you are really trying to do, I could maybe post some source code for it (having once fixed a keyboard layout bug in Firefox I know the docs pretty well)
Mecki
Ok!My application accepts default(English) keyboard layout. When it it installed in a mac machine whose default language is "Danish" but still it accepts the default keytext of English.eg: if you press '@' in Danish keyboard it types in '"' which is not actually happening in my application. Basically when my application is installed in any other locale language it should automatically configure the keyboard layout. User need not have to select it manually.
frederic
Hi Mecki,very simple requirement for your understanding.i have 2 radio buttons in my application. "Danish" and "English". On Danish radio option select my application should accept danish language entry from keyboard and when english is selected it should accept "default US english". Or by default it should accept Danish as default language. Please guide me how can i achieve this requirement. I would really appreciate if you can help me with come code. thank !
frederic
@frederic: I still fail to see why you need to care for the keyboard layout at all. I have written maybe almost 100 Cocoa applications and never even once had to care for the keyboard layout. All my applications work fine with any existing keyboard layout in the whole world. If you place a NSTextField in your UI, it will accept input of any keyboard layout in the wold and convert any keyboard layout in the world to correct Unicode for you. So please explain why you would care for the keyboard layout at all. Cocoa programmers usually never care for the keyboard layout.
Mecki