Okay, so my current project is very simple, just this:
// typewriter.cpp //////////////////////////////////////////////////////////////
// An SFML program that runs in the background /////////////////////////////////
// playing audio feedback with each keypress ///////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//#include <std_files>
//#include "Headers.h"
//#include "Headers.hpp"
//#include "Source.cpp"
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
int main()
{ sf::SoundBuffer buffer;
if (!buffer.loadFromFile("./chime.ogg"))
{ return -1;
}
else
{ sf::Sound chime;
chime.setBuffer(buffer);
sf::RenderWindow window(sf::VideoMode(300, 20), "typewriter 1.0");
while (window.isOpen())
{ sf::Event event;
while (window.pollEvent(event))
{ if(event.type == sf::Event::Closed)
{ window.close();
}
if (event.type == sf::Event::KeyPressed)
{ if (event.key.code == sf::Keyboard::K)
{ chime.play();
}
}
}
window.clear();
// eventually this can be some sort of logo
window.display();
}
}
return 0;
}
The goal of the program is to create a cross-platform app that can provide audio feedback while typing, ie playing the sound of a typewriter click every time a key is pressed, so that the user can have feedback while typing beyond just seeing the output on the screen (also keys could be assigned to a specific pitched sound, but thats obviously more complex.
The goal with this project is to create an app that users can start, and run in the background while working on other tasks. The fairly obvious problem is that the program only works when its window is the focus, not useful when working in another application like a text editor or browser. Is there any way that the program could be set up to receive key inputs in the background, so that the sound will play even when another program is the focus?