<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Global hotkeys in Cocoa on Snow Leopard</title>
	<atom:link href="http://cocoakids.net/14-global-hotkeys-in-cocoa-on-snow-leopard/feed" rel="self" type="application/rss+xml" />
	<link>http://cocoakids.net/14-global-hotkeys-in-cocoa-on-snow-leopard</link>
	<description>Sweet bits of cocoa programming</description>
	<lastBuildDate>Sat, 06 Feb 2010 08:08:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: eimantas</title>
		<link>http://cocoakids.net/14-global-hotkeys-in-cocoa-on-snow-leopard/comment-page-1#comment-65</link>
		<dc:creator>eimantas</dc:creator>
		<pubDate>Tue, 26 Jan 2010 10:18:55 +0000</pubDate>
		<guid isPermaLink="false">http://cocoakids.net/?p=14#comment-65</guid>
		<description>Alice - since you can&#039;t modify global event - it gets passed further, hence triggering the quick look shortcut.</description>
		<content:encoded><![CDATA[<p>Alice &#8211; since you can&#8217;t modify global event &#8211; it gets passed further, hence triggering the quick look shortcut.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alice</title>
		<link>http://cocoakids.net/14-global-hotkeys-in-cocoa-on-snow-leopard/comment-page-1#comment-64</link>
		<dc:creator>Alice</dc:creator>
		<pubDate>Mon, 25 Jan 2010 19:43:49 +0000</pubDate>
		<guid isPermaLink="false">http://cocoakids.net/?p=14#comment-64</guid>
		<description>Are you sure this works? Whenever my shortcuts includes pressing the spacebar and I&#039;m currently in the Finder, my event handling is done, but also Quicklook is shown.
I fear one has to use Carbon to really achieve the desired effect...</description>
		<content:encoded><![CDATA[<p>Are you sure this works? Whenever my shortcuts includes pressing the spacebar and I&#8217;m currently in the Finder, my event handling is done, but also Quicklook is shown.<br />
I fear one has to use Carbon to really achieve the desired effect&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lithiumstarfish</title>
		<link>http://cocoakids.net/14-global-hotkeys-in-cocoa-on-snow-leopard/comment-page-1#comment-34</link>
		<dc:creator>lithiumstarfish</dc:creator>
		<pubDate>Tue, 10 Nov 2009 19:49:29 +0000</pubDate>
		<guid isPermaLink="false">http://cocoakids.net/?p=14#comment-34</guid>
		<description>I see. My app is a background app so it shouldn&#039;t ever be active :(</description>
		<content:encoded><![CDATA[<p>I see. My app is a background app so it shouldn&#8217;t ever be active :(</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: eimantas</title>
		<link>http://cocoakids.net/14-global-hotkeys-in-cocoa-on-snow-leopard/comment-page-1#comment-33</link>
		<dc:creator>eimantas</dc:creator>
		<pubDate>Tue, 10 Nov 2009 18:51:12 +0000</pubDate>
		<guid isPermaLink="false">http://cocoakids.net/?p=14#comment-33</guid>
		<description>You&#039;re right again. I created test app with your code and it works nicely for me. The app makes beep only when it&#039;s active. It happens because global monitor events does not route from your own app. Since you added event handler for any NSKeyDown event - it will make beeps when it&#039;s active. On any key press, that is.</description>
		<content:encoded><![CDATA[<p>You&#8217;re right again. I created test app with your code and it works nicely for me. The app makes beep only when it&#8217;s active. It happens because global monitor events does not route from your own app. Since you added event handler for any NSKeyDown event &#8211; it will make beeps when it&#8217;s active. On any key press, that is.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lithiumstarfish</title>
		<link>http://cocoakids.net/14-global-hotkeys-in-cocoa-on-snow-leopard/comment-page-1#comment-32</link>
		<dc:creator>lithiumstarfish</dc:creator>
		<pubDate>Tue, 10 Nov 2009 18:22:34 +0000</pubDate>
		<guid isPermaLink="false">http://cocoakids.net/?p=14#comment-32</guid>
		<description>The API does confirm that addGlobalMonitorForEventsMatchingMask returns void, however, we still need to include (NSEvent *event) because it is the parameter, without it you are not able to access the event to get the modifierFlags or keyCode.

+ (id)addGlobalMonitorForEventsMatchingMask:(NSEventMask)mask handler:(void (^)(NSEvent*))block

The weird thing is that my program does respond to the hotkey, it just also makes the alert sound...it&#039;s like its not telling the system that it responsible for handling this key press.</description>
		<content:encoded><![CDATA[<p>The API does confirm that addGlobalMonitorForEventsMatchingMask returns void, however, we still need to include (NSEvent *event) because it is the parameter, without it you are not able to access the event to get the modifierFlags or keyCode.</p>
<p>+ (id)addGlobalMonitorForEventsMatchingMask:(NSEventMask)mask handler:(void (^)(NSEvent*))block</p>
<p>The weird thing is that my program does respond to the hotkey, it just also makes the alert sound&#8230;it&#8217;s like its not telling the system that it responsible for handling this key press.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: eimantas</title>
		<link>http://cocoakids.net/14-global-hotkeys-in-cocoa-on-snow-leopard/comment-page-1#comment-31</link>
		<dc:creator>eimantas</dc:creator>
		<pubDate>Tue, 10 Nov 2009 17:54:14 +0000</pubDate>
		<guid isPermaLink="false">http://cocoakids.net/?p=14#comment-31</guid>
		<description>Mkay

Now i found another error in my code.

When you add local event monitor - event handler block returns NSEvent object so you can modify it. In case of global events - your handler returns void since you can&#039;t modify global events. This might be the cause of your beep.

Ergo, you should change your code from this: [NSEvent addGlobalMonitorForEventsMatchingMask:NSKeyDownMask handler:&lt;strong&gt;^(NSEvent *event)&lt;/strong&gt; {

to this: [NSEvent addGlobalMonitorForEventsMatchingMask:NSKeyDownMask handler:&lt;strong&gt;^&lt;/strong&gt;{

I guess i should reread my post a few times before posting it ,)</description>
		<content:encoded><![CDATA[<p>Mkay</p>
<p>Now i found another error in my code.</p>
<p>When you add local event monitor &#8211; event handler block returns NSEvent object so you can modify it. In case of global events &#8211; your handler returns void since you can&#8217;t modify global events. This might be the cause of your beep.</p>
<p>Ergo, you should change your code from this: [NSEvent addGlobalMonitorForEventsMatchingMask:NSKeyDownMask handler:<strong>^(NSEvent *event)</strong> {</p>
<p>to this: [NSEvent addGlobalMonitorForEventsMatchingMask:NSKeyDownMask handler:<strong>^</strong>{</p>
<p>I guess i should reread my post a few times before posting it ,)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lithiumstarfish</title>
		<link>http://cocoakids.net/14-global-hotkeys-in-cocoa-on-snow-leopard/comment-page-1#comment-30</link>
		<dc:creator>lithiumstarfish</dc:creator>
		<pubDate>Tue, 10 Nov 2009 13:55:55 +0000</pubDate>
		<guid isPermaLink="false">http://cocoakids.net/?p=14#comment-30</guid>
		<description>I tried using F11 as my hot key (as this is the key I use with another app without problems). I made sure to remove the default functionality (expose) in system preferences. My app only seems to make the alert noise whenever Xcode or Finder has the focus, however, I&#039;m wondering how the other app that I use gets around this.

As for the second part of my post here is the code I wrote to show what is being pressed:

myHotKey = [NSEvent addGlobalMonitorForEventsMatchingMask:NSKeyDownMask handler:^(NSEvent *event) {

	NSString *keysPressed = @&quot;&quot;;
	if ([event modifierFlags] &amp; NSControlKeyMask)
		keysPressed = [NSString stringWithFormat:@&quot;%@^&quot;, keysPressed];
	if ([event modifierFlags] &amp; NSAlternateKeyMask)
		keysPressed = [NSString stringWithFormat:@&quot;%@?&quot;, keysPressed];
	if ([event modifierFlags] &amp; NSShiftKeyMask)
		keysPressed = [NSString stringWithFormat:@&quot;%@?&quot;, keysPressed];
	if ([event modifierFlags] &amp; NSCommandKeyMask)
		keysPressed = [NSString stringWithFormat:@&quot;%@?&quot;, keysPressed];
	keysPressed = [NSString stringWithFormat:@&quot;%@%@&quot;, keysPressed, [[event charactersIgnoringModifiers] uppercaseString]];
	NSLog(@&quot;%@&quot;, keysPressed);
   
	if ([event keyCode] == 103) //F11
		[[NSNotificationCenter defaultCenter] postNotificationName:@&quot;myNotification&quot; object:nil];
}];</description>
		<content:encoded><![CDATA[<p>I tried using F11 as my hot key (as this is the key I use with another app without problems). I made sure to remove the default functionality (expose) in system preferences. My app only seems to make the alert noise whenever Xcode or Finder has the focus, however, I&#8217;m wondering how the other app that I use gets around this.</p>
<p>As for the second part of my post here is the code I wrote to show what is being pressed:</p>
<p>myHotKey = [NSEvent addGlobalMonitorForEventsMatchingMask:NSKeyDownMask handler:^(NSEvent *event) {</p>
<p>	NSString *keysPressed = @"";<br />
	if ([event modifierFlags] &amp; NSControlKeyMask)<br />
		keysPressed = [NSString stringWithFormat:@"%@^", keysPressed];<br />
	if ([event modifierFlags] &amp; NSAlternateKeyMask)<br />
		keysPressed = [NSString stringWithFormat:@"%@?", keysPressed];<br />
	if ([event modifierFlags] &amp; NSShiftKeyMask)<br />
		keysPressed = [NSString stringWithFormat:@"%@?", keysPressed];<br />
	if ([event modifierFlags] &amp; NSCommandKeyMask)<br />
		keysPressed = [NSString stringWithFormat:@"%@?", keysPressed];<br />
	keysPressed = [NSString stringWithFormat:@"%@%@", keysPressed, [[event charactersIgnoringModifiers] uppercaseString]];<br />
	NSLog(@&#8221;%@&#8221;, keysPressed);</p>
<p>	if ([event keyCode] == 103) //F11<br />
		[[NSNotificationCenter defaultCenter] postNotificationName:@&#8221;myNotification&#8221; object:nil];<br />
}];</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: eimantas</title>
		<link>http://cocoakids.net/14-global-hotkeys-in-cocoa-on-snow-leopard/comment-page-1#comment-29</link>
		<dc:creator>eimantas</dc:creator>
		<pubDate>Mon, 09 Nov 2009 20:42:25 +0000</pubDate>
		<guid isPermaLink="false">http://cocoakids.net/?p=14#comment-29</guid>
		<description>Regarding the alert noises - it&#039;s probably because the keystroke is already taken by an active app or system (in which case my code would have mistake regarding the activated keystroke. thanks for noticing).

And regarding the display of the characters, I&#039;d suggest &lt;a href=&quot;http://wafflesoftware.net/shortcut/&quot; title=&quot;Wafflesoft shortcut recorder&quot; rel=&quot;nofollow&quot;&gt;shortcut recorder from wafflesoft&lt;/a&gt;.</description>
		<content:encoded><![CDATA[<p>Regarding the alert noises &#8211; it&#8217;s probably because the keystroke is already taken by an active app or system (in which case my code would have mistake regarding the activated keystroke. thanks for noticing).</p>
<p>And regarding the display of the characters, I&#8217;d suggest <a href="http://wafflesoftware.net/shortcut/" title="Wafflesoft shortcut recorder" rel="nofollow">shortcut recorder from wafflesoft</a>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: lithiumstarfish</title>
		<link>http://cocoakids.net/14-global-hotkeys-in-cocoa-on-snow-leopard/comment-page-1#comment-28</link>
		<dc:creator>lithiumstarfish</dc:creator>
		<pubDate>Mon, 09 Nov 2009 19:14:04 +0000</pubDate>
		<guid isPermaLink="false">http://cocoakids.net/?p=14#comment-28</guid>
		<description>I am trying to setup my app to have user configurable hot keys...however, when I use the above method the system makes the alert noise. Is there anything I can do to make my app &#039;consume&#039; the key press(s) and not cause the alert noise?

Also, is there an easy way to translate the keys codes into their printable characters? For example, I want to have a text box display &#039;⌘ + X&#039; whenever ⌘ + X is pressed.</description>
		<content:encoded><![CDATA[<p>I am trying to setup my app to have user configurable hot keys&#8230;however, when I use the above method the system makes the alert noise. Is there anything I can do to make my app &#8216;consume&#8217; the key press(s) and not cause the alert noise?</p>
<p>Also, is there an easy way to translate the keys codes into their printable characters? For example, I want to have a text box display &#8216;⌘ + X&#8217; whenever ⌘ + X is pressed.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Antonio Salazar Cardozo</title>
		<link>http://cocoakids.net/14-global-hotkeys-in-cocoa-on-snow-leopard/comment-page-1#comment-27</link>
		<dc:creator>Antonio Salazar Cardozo</dc:creator>
		<pubDate>Sun, 08 Nov 2009 23:52:13 +0000</pubDate>
		<guid isPermaLink="false">http://cocoakids.net/?p=14#comment-27</guid>
		<description>Do note that you need to have access for assistive devices enabled in the Unviersal Access prefpane for this to work. Alternatively, you need to have your app marked as a trusted accessibility app, the process for which I&#039;m not sure of.</description>
		<content:encoded><![CDATA[<p>Do note that you need to have access for assistive devices enabled in the Unviersal Access prefpane for this to work. Alternatively, you need to have your app marked as a trusted accessibility app, the process for which I&#8217;m not sure of.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
