cocoa / objective c : How to know which control is under the cursor? - objective-c

I am making an application which will detect global mouse events and log the action performed.
For example : If i click on close/minimize button on finder(or any other app like firefox,safari etc) then the app should be able to detect this. Till now i could find the window name under the cursor when click is made. So i can capture mouse click events. But i am not able to find on how to detect exact which button/control was clicked on that window.
I am using NSEvent addGlobalMonitorForEventsMatchingMask:(NSLeftMouseDownMask| NSRightMouseDownMask ) handler:^(NSEvent *event){ } for capturing mouse events.
So Is there a way i could know which button/control was clicked? Or in case a folder icon is clicked on finder then is there a way to know that selected folder name.
Thanks in advance!

Its simple. Check UIElementInspector example in dev.apple.com mac library. Following is the link:
https://developer.apple.com/library/mac/#samplecode/UIElementInspector/Introduction/Intro.html

Related

How to implement a pop-up window when hovering on a URL link

I'm relatively new to Cocoa application. In my application (MacOS), I already mark the text if it contains image url link. What I'm trying doing now is that when the mouse hover (without clicking) on the link, the application will open an NSPanel (sorry, if it's inaccurate) and show the content of the image url. Also, the panel/window will be closed automatically when mouse move out of the text.
I've tried something such as "floating window/panel/quicklook", but the search result isn't close to what I want. Could anyone please give me some keywords so I can try to find the solution by myself? Thank you.

Check if software keyboard is open in Windows Phone 8?

I want to check if the software keyboard is open in Windows Phone 8. I have found some sparse information that this is possible using CoreWindow.IsKeyboardInputEnabled, but I can't find any way to implement this. I have found sample code only for C++, which I don't understand at all.
I use VB, however I can read C# enough to figure it out if I can get a C# example.
Whatever I do I always get a null/nothing value. The following code compiles and runs, but c is 'nothing' when the app crashes at the if c.IsKeyboarInputEnabled... line.
Dim c as CoreWindow
c = CoreWindow.GetForCurrentThread
if c.IsKeyboardInputEnabled then...
I know I need to give 'c' a value, but can't figure out how. I've also tried:
Dim c as CoreWindow = New CoreWindow
which the editor flags as an error and thus won't compile.
If it's relevant, what I am trying to do is ensure my navigation is consistent. Currently, a tap on a particular screen element should close that element. However, if the keyboard is open, I want that tap to simply close the keyboard and leave the tapped item open. I believe this is the more intuitive and consistent approach for the user.
I think the only way to achieve this functionality is to know if the keyboard is open before determining what to do with any open panels.
e.g.
[when screen tapped and a popup is expanded]
If [keyboard visible] then [close keyboard] else [close tapped item]
I don't think there is any official API to detect the opening and closing of the SIP but one workaround might be to check if any of your TextBoxes have focus.
You can do this by overriding GetFocus and LostFocus for each TextBox.
To close keyboard, just set the focus to the ContentPanel(or any other grid).
Let me know if this works.

VB.NET Keybord tracker

Hello I have a VB NET application and I would like to add it a keybord key pressed catching system so I can track any keybord key that is pressed on any application that is running on my computer and uses keybord.
If someone has any idea thanks for sharing it.
I Hope my question was clear.
Thanks.
You will need to use a Global KeyBoard hook, look at this CodePlex Project. It will allow you to intercept the Global Keyboard events.
From Link:
This library allows you to tap keyboard and mouse and to detect and
record their activity even when an application is inactive and runs in
background.
This library attaches to windows global hooks, tracks keyboard and
mouse clicks and movement and raises common .NET events with
KeyEventArgs and MouseEventArgs, so you can easily retrieve any
information you need:

How to simulate mouse clicks?

I was wondering how to create a sort of auto clicker using VB.NET.
I would basicly have the click coordinates pre-defined and the clicks, which would have to be separated by delays I guess since I want more than one to happen periodically, would happen outside of the application window (I read this envolves extra system hooks?).
The only code I have been able to find is related to clicks on the application window, which is not what I am looking for.
In short: I want to click a button on the app window, which would initiate a number of clicks on certain pre-defined screen coordinates.
Thanks in advance :)
See this discussion on social.msdn: Simulate a mouse click in a program.
Uses winapi: SetCursorPos, GetCursorPos and mouse_event.
I believe you need to P/Invoke into Windows to accomplish this.
Have a look at the SendInput function.
If you are using automate the program,that program have some tabindex in order to relevant control.then you can use;
SendKeys.Send("{TAB}");
SendKeys.Send("{ENTER}");
it is more accurate on desktop application

Closing frontmost window in Cocoa in an app without a menu bar

I am building a StatusBar App in Cocoa, therefore I have no menu. Having no menu implies not having a "File > Close" menu item, which normally listens to the shortcut "Command + W".
From my StatusBar App the user may open a window to change the preferences and that's where I'm running into problems: The user can only close the window by pressing the red dot with the mouse. However, like alle applications I want to support the "Command + W" shortcut as well.
At the moment I see two possibilities to solve this issue:
Place an invisible button on the window which listens to the shortcut.
Add an application-wide listener for the shortcut and contact the window manually.
Both solutions feel like a misuse of the system. The first solution can lead to unexpected behaviour (the window closes if the user hits the invisible button by chance) and the second solution will still result in a beep, since the window does not know that it handles such a shortcut.
Is there an elegant way to solve this problem? Since the view should know what to do, a solution with just Interface Builder would be perfect. If there is no elegant way, is there a way to enhance the solutions mentioned?
Thanks in advance!
If you put a File > Close menu item in your MainMenu nib, the shortcut will work, even though the menu isn't visible.
If you choose to implement an app-wide listener for the shortcut instead, you can get rid of the beep by returning nil from the block, so that the original event doesn't get passed on.