Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Global Hotkeys on OS X  (Read 2955 times)

0 Members and 1 Guest are viewing this topic.

xqbt

  • Newbie
  • *
  • Posts: 30
    • View Profile
Global Hotkeys on OS X
« on: January 19, 2016, 11:21:35 pm »
I am trying to make use of global hotkeys in my C++ SFML program.

Specifically, I am trying to do that when the program is out of focus and invisible. The second is achievable by calling setVisible(false).

So, I have success using:
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
I just poll keyboard every 10 milliseconds and it works.
BUT it works only only on windows and linux.
Does not work on mac.
On mac, it works only when window is in focus.

Is there a workaround?
Could anyone please help me achieve the functionality?
« Last Edit: January 19, 2016, 11:25:06 pm by xqbt »

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Global Hotkeys on OS X
« Reply #1 on: January 19, 2016, 11:50:32 pm »
What exactly are you trying to accomplish? A keylogger? Anyways, without looking into it - it is probably an intentional limitation of OSX.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

xqbt

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Global Hotkeys on OS X
« Reply #2 on: January 20, 2016, 12:02:49 am »
No, not a keylogger :) Global hotkeys - unfold the program, do some action, stuff like that.

I am trying to use DDHotKey
https://github.com/davedelong/DDHotKey
But I simply do not understand where I embed the code and which callback function I have to pass. (I have almost no experience using cocoa or carbon). No basic understanding.

I thought maybe someone has done something like that before.
« Last Edit: January 20, 2016, 12:04:37 am by xqbt »

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Global Hotkeys on OS X
« Reply #3 on: January 20, 2016, 11:12:34 am »
zsbzsb is right, SFML cannot do that for you. The thing is, on OS X you receive keyboard events only when the window is active.
SFML / OS X developer

xqbt

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Global Hotkeys on OS X
« Reply #4 on: January 22, 2016, 12:54:06 am »
Yeah, it seems to be that way. Anyway, thanks.

 

anything