Return focus to Editor after clicking a button in

2019-04-15 23:58发布

问题:

I have created a virtual keyboard library in adobe flex.

I have already created an ANE for Windows to set the keyboad always on top and non focusable. Using:

int exstyle = GetWindowLong(hwnd3, GWL_EXSTYLE);
exstyle |= WS_EX_NOACTIVATE; 

But now I have to create an ANE for the mac (OS 10.7)

  1. I have to access the keyboard (keywindow) from the running flex application
  2. Set it always on top and non focusable(even if I click on the keys or select keyboard language from combobox of the keyboard it will not get focused). So that the cursor will always stay in the editor.

I have tested a sample mac application (for testing purpose only) by using

setLevel:NSFloatingWindowLevel 

However when I click on the blank area of the window it is not getting focused (cursor stays in my editor/textarea), but when I click on any button on it that button get focused.

How to access the flex virtual keyboard and set it to No-Activate mode in Mac

------------------------------ADDED--------------------------------------------------------

I have used this code to set my Flex application at top of all windows NSWindow

*myMainWindow = [[[NSApplication sharedApplication] windows] objectAtIndex:0];
//[myMainWindow setLevel:NSFloatingWindowLevel]; 
[myMainWindow setLevel:NSMainMenuWindowLevel+1]; 

But I want to deactivate that window so that it won't get focused. like KeyboardViewer in mac. The KeyEvent should be redirected to the current TextInput for every click of the key(Flex Keyboard).

Please help me with your suggestions.

回答1:

Are you saying you created an ANE in the keyboard app that is trying to convert the Window? An ANE seems to be the way to go unless you can configure the flex application to create its main window as an NSPanel instead of an NSWindow.

What you can do is create a panel the same size as the window then set the panel's content view to the window's content view. That will move all the window's contents to your newly created panel. Then call orderOut on the main window and makeKeyAndOrderFront on the panel. Here is similar code we had in Connect:

NSWindow *mainWindow = [[NSApp windows] objectAtIndex: 0];
NSView *mainContentView = [mainWindow contentView];

NSPanel *mainPanel = [[NSPanel alloc] initWithContentRect:[mainContentView frame]
                 styleMask:NSBorderlessWindowMask | NSNonactivatingPanelMask
                backing:NSBackingStoreBuffered defer:YES];

[mainPanel setContentView:mainContentView];
[mainPanel setLevel:NSScreenSaverWindowLevel];

[mainPanel makeKeyAndOrderFront:nil];
[mainContentView orderOut:nil];