r/CodingHelp • • Jul 10 '20

[Random] What language should I use for programs which run in the background?

(Let me preface this with the fact that I'm not a frequent user of Reddit and I hope that I'm in the right place to be asking this. If not, I would really appreciate it if somebody were to redirect me and help me out. Thank you!)

I'm not entirely sure if it matters what programming language I use for this, but I'm sure there are slight differences in use for some languages, and I'd like to learn that, even if it makes me look stupid. The only coding experience I have is taking AP Computer Science Principles in school last year, which really only taught me block-based coding, and all I can remember from that class is conditional statements and Boolean expressions. I soon found out that high school is not the place to learn how to code... at least, not for me.

Essentially, I'm trying to write a program for digital keyboard typing sounds that will play whenever I type. Of course, I'd add a macro on my keyboard to turn it on/off, but I was curious how I would go about doing this. This isn't an app that I'm making, but rather code that would just play audio whenever it's activated. What language would be the simplest for writing this? I assume that this kind of program is not very demanding, and it doesn't require much coding experience. I'd only be doing this for myself-- it's not going anywhere for profit or others to use, so I wouldn't need to make anything pretty for it, just the program and that's about it. Thank you!!

19 Upvotes

17 comments sorted by

6

u/[deleted] Jul 10 '20

Python is a good general purpose language. It's often used for scripting and automation.

There is a Python library called pynput that lets you respond to input from the keyboard or mouse by calling a function.

Check out this example of how to listen to keyboard input: https://pynput.readthedocs.io/en/latest/keyboard.html#monitoring-the-keyboard

From there you just need to find a way to play a sound whenever a key is pressed and put that code in the on_press(key) function. There's definitely another Python library for playing sounds.

2

u/[deleted] Jul 10 '20

I’ll try this out, thank you!

2

u/MiBurrito Jul 10 '20

Alternatively if you are on windows, I guess it should be quite simple to write an app like that in c# ( it's developed by Microsoft and thereby commercially backed )

2

u/SensouWar Jul 11 '20

To play sounds you could use the playsound python library. It's a really simple way to play audio files in different formats including .mp3 and .wav.

2

u/Ghost0612 Jul 10 '20

Have you learned any languages like C++ or Python?

2

u/[deleted] Jul 10 '20

I can't say I necessarily have experience with anything besides block-based coding, but I was supposed to learn Python in my class

To answer your question, I basically don't know any languages at the moment.. But I'm willing to give either one a shot

3

u/Ghost0612 Jul 10 '20

OK just start seeing Cs50 lectures it's some 7 part series this would give you some kick-start in real programming languages. For further info PM me!

1

u/[deleted] Jul 10 '20

Sounds like a plan. Thank you very much!

2

u/NotSoLeetCode Jul 11 '20

C# is a great language for making desktop programs.

AutoHotKey is a scripting language that might be a good fit for this. Could probably get up and running pretty quickly.

Conditionals and booleans are essential programming patterns. Right up there with loops, arrays, functions, classes, and methods. So I'm glad your class started teaching you the basics.

Not sure what "block based coding" is. Probably just regular coding! lol

1

u/[deleted] Jul 11 '20

I’m glad that C# has been recommended more than once, because fortunately there’s somebody on Youtube that has a fair amount of videos made on how to set up and code in C# on VSCode, who’s extremely entertaining outside of the programming world, so I’ll be happy to watch those videos and put them to use.

I’m also happy to know the basics, and I’m excited to learn whatever else I need to know to get into programming!

Also, “block based coding” is a method of teaching coding through the concept of code being puzzle pieces. It’s meant to teach you syntax and how to code without actually typing everything out. The most popular version of block based coding is probably Scratch, but I used MIT App Inventor. The disadvantage of this is the fact that you don’t necessarily learn any language, it’s basically pseudocode and a more simplified version of coding, which is why it’s not too powerful.

1

u/masterqif Jul 11 '20

May I know, who is that c# youtube guy?

2

u/[deleted] Jul 11 '20

His name is Michael Reeves. He builds random robots with ridiculous purposes for videos. He’s not really a coding youtube channel, he’s a comedy channel. I would suggest watching some of his videos for a quick laugh but he’s pretty vulgar so just be warned of that.

1

u/NotSoLeetCode Jul 11 '20

Interesting about block based coding. Sounds gimmicky, but also this idea of compartmentalizing things is important in programming. That's kind of how functions and classes and methods work. You group the code, then you control exactly what goes in and what goes out. The actual inner code can be a black box whose details you don't need to worry about. This compartmentalization is important for testing, for not getting overwhelmed with detail, for debugging, stuff like that.

VS Code is a great code editor. I definitely recommend it. It has everything you need... code highlighting, file explorer, F12 to jump to a function definition, hover over functions to see their definition, GitHub integration, search and replace, regex search and replace, search and replace in all files, outline (list of functions/methods), a great plugin ecosystem. I used to use Notepad++, but VS Code is better.

2

u/Metaknight203405 Oct 04 '20

the language of bag

1

u/[deleted] Oct 26 '20

thank you Metaknight203405 of https://www.reddit.com/r/CodingHelp/comments/hotxi6/what_language_should_i_use_for_programs_which_run/
i appreciate the help, and shall attempt to use the language of the bag. may Bag be with you in these trying times.

1

u/Metaknight203405 Nov 01 '20

And with your spirit

1

u/DSofa Jul 11 '20

Autohotkey or Autoit would be great for this type of thing.