can I display realtime feedback in a terminal game? - c

I'm trying to write a simple terminal-based dungeon-style game in C, but I want to give the user real-time feedback on various processes that they affect.
I remember using kbhit() years ago, but I also remember the cpu going to 100% during the life of the program. I'd like to avoid this entirely. And I'm working in Linux now.
Let's say that you're in a dungeon in a text-based adventure game. The dungeon is sealed off. There's only so much air in the room. The longer you remain there, the lower the oxygen gets. I want to report the oxygen level in the room in real-time, while at the same time accepting commands from the user.
Is there a way to do this?
EDIT: The one idea I had was to use two terminal windows. Commands are taken in one terminal, the results of those commands could be written to a text file. The other terminal will have a program running that runs real-time stuff, and checks periodically on the same text file for updates on rates, etc. Ideally, I'd like to do this in one window.

Sure there is a way to do that. Have a look at ncurses. I think that is the way to go.

Related

How to send waypoints programmatically to drone?

I am very new at this and trying to get an understanding of this. I have read a lot on the DroneKit-Python site trying to figure out how exactly am I able to communicate with it.
Drone I am currently using is Iris+
I have looked more and there are software that already provide this, but I want to be able to control it plus more.
I want to set waypoints, tell it to then fly give the way points and keep going to them. Also, to be able to arm itself, which is in the example, and override the safety mechanism.
Here is the basic of what I am trying to use it for. Have it fly up at a certain time. Go to the waypoints 1,2,3,1,etc.. Then after X amount of time or on low battery go back to launch point and land.
I have found plenty of code that provides what i need to do, though I don't know if it will work and more importantly I don't even know how to start programming for this. Maybe I have the wrong approach in doing this?
I kind of want this to be a light API, so that in the future I can make a simple UI on my phone and insert some coordinates to give it ways points and that is it. I know there is software out there already that does it, but I want to remove the need for touching the drone. I want it to start and end autonomously.
If anyone could help provide some info that much would be greatly appreciated.
Assuming you have no companion computer (Iris+ does not by default), you are OK with running a ground station app (you won't be out of range to send commands to "end mission on time expiry") and that driving the behaviour from your phone is important, I would be looking at DroneKit Android.
Some notes:
You're going to have to touch the drone at some point to attach the
batteries.
You can arm the device from dronekit
You can override the safety mechanism from a script. I hope you have
a lot of money to pay for the new drones you're going to have to buy when they crash and all the litigation from damaged people and property (in other words "don't do it".
The default behaviour is to return the device to launch (RTL) on low battery. This is convigurable
Setting a time is more "problematic". You can have a timer in a script that then sends return-to-launch but the script needs to be connected to the UAV. This means that either you have to be running in a connected ground station (which might potentially be out of range) or on a companion computer.
Iris+ does not have a companion computer. You have to install one or connect from a Ground Control Station.
DroneKit-Python runs on Linux, MacOSX or Windows. You can't just run it on an ordinary phone, though you could find some other mechanism to send messages/scripts to it running on a companion Computer.
DroneKit Android runs on Android. We do have a planned iOS version too. In theory these could run on a companion computer, but in practice currently these are only used as ground stations.

How to get started on creating a safe that will open and close upon entering a passcode into it?

I want to work on a project dealing with some hardware things but I have no knowledge in this area and I would really appreciate some help with getting started.
I am programming in Node.js so I have had a look at NodeBots and Arduino; however, I am not sure if this is the right place to even start.
The main thing I want to be able to do is:
create a safe where it will open when I enter the correct passcode into an iPad or some touch screen
be able to set the passcode
When working on such a project, do I need the hardware first? (If so, what are some things I should get?)
Secondly, where can I start coding and what are good languages for this? (I am unsure as to which aspect of this project I should focus on first)
I made one with a keypad (not connected to other devices, but it's similar). And, according to my experience, the mechanical part is the worst: designing and building the safe (I used plexiglass) was the worst thing.
As for your questions, I think that yes, you should start with the hardware design. Or at least choose
how are ou closing/opening the door? I used a stepper motor, but there are tons of choices - door locks, servomotors, dc motors.....
how are you detecting if it is open or closed?
what will be the interface? You spoke about iPad, so I suppose you want some bluetooth apple-enabled devices.
Then you will be able to start coding. But the code will be really simple once you got what the hardware will look like (in the end, it's just "wait for the correct passcode, then open the safe, then close it again").

OS X Intercept Keyboard Events to Password Forms Elements

I am currently creating a c program that counts all of the keys I press in a day and sorts the key types by amount, so I can tell which ones I press most often. It was more of a side project than anything else but I have become annoyed with the fact that my program doesn't seem to be able to intercept any input to password fields. I suppose this is a good thing, but I have been spending hours looking at documentation and trying to figure how to do this. I am not trying to create any sort of malicious software. Is there a way around this? My program is running as root. I am using the ApplicationServices framework and CGEventRef and the CGEventTapCreate funcion. Should I be using a different framework or struct? Also, is there a difference between kCGHIDEventTap, kCGSessionEventTap, and kCGAnnotatedSessionEventTap? I have tried using each of them and it does not seem to make a difference in my program.
I am running this on OS X 10.9
UPDATE
Apparently I cannot capture keystrokes going to terminal either, which is where I spend most of my time on my laptop. This is a problem.
What you want is fairly complicated and requires a kernel extension. The interprocess communication is also not trivial. Take a look at logKext, specifically logKext.cpp. That project actually logs the keystrokes to an encrypted file. You should be able to pull everything you need from it.

Prevent Mac Laptop from sleeping when closed?

I'm writing a program in C and want it to have an option that will keep a mac laptop awake even if the lid is closed so processes can continue. There seems to be very little information available on this topic so I really don't know where to begin. If anyone knows how to accomplish this or where I can find more information I would really appreciate (i.e. will I need to work with the BIOS for this or are there built in functions?). Also, if it's easier to do it in another language that is fine as I'm not stubbornly set on using C.
You need to write a kernel extension for this. The OS doesn't support it by default because the laptops aren't designed to properly cool themselves with the lid closed and internal display enabled. SleepLess is a $10 utility that'll do what you want, too. If you warp the display or something, it's your own fault. :-).
If you want to write something yourself, LidSleep.kext looks like a good start (it does the opposite, i.e. sleeping on lid close) and comes with source code.
(It is possible and supported to wake up some Mac laptops with the screen closed by using an external input device.)
You can do this using the I/O Kit framework, see QA1340 listing 2 for sample code using IOPMAssertionCreateWithName to temporarily prevent sleep.
The link to LidSleep.kext listed above is not working, so I can inform that the author of NoSleep has made the source code available here, so you can see for yourself how it can be done:
https://code.google.com/p/macosx-nosleep-extension/
If your laptop is a reasonably recent model, you don't need to add anything. If you are running Lion, it simply works. If you're running an older OS you have to wake up the laptop by sending it a keystroke or mouse click from an external keyboard or mouse. See http://support.apple.com/kb/ht3131

prevent screen capture

i am developing a video player i silverlight
i wanna something to prevent recording or screen capturing
i thought about hacking the windows APIs and stop my program from running if there was any of those capturing software asking the user to close it first but i donno how to do this
is there another solution ??!!!!
It's simple not possible. If you try it, you're only going to annoy people.
Even 'hacking the windows API' would not work, since the OS itself could be run inside a VM.
I hate to be a downer, but task is impossible to fully accomplish.
If you were somehow able to hook the keyboard (from a silverlight app no-less) I would certainly hope that whatever AV the user is running would throw up some red flags.
Also what if the user doesn't use the standard (alt)+prtscr? A third-party tool might use a different key-combo. Also, I've written a screen-grabber with the GDI+ API, and there's no way to disable something that low-level.
What about attached capture-cards? What if your app is running in a VM or over remote-desktop?
If you are that deeply concerned about protection your HD content, watermark it, or make the user pay for it first.
All-in-all, as soon as your content's data enters your user's computer, they can duplicate it.
You could go about using a key hook system, stopping the user pressing the print screen key on the keyboard, that would be a start. There aren't many systems which stop users from print screening video specifically. You might want to try just watermarking your video instead? At least then people know that the video was originally sourced from you.
The solution is not to allow your application to run on a computer, but instead target a device such as a phone. Computers will always allow some kind of screen capture and video capture but this is much harder and less likely to be tackled if you restrict to only playing on certain devices.
How badly do you need this? There are many ways to defeat screen capture protection: for instance, aiming a video recorder at the computer screen (or looping output to a TV with a capture card, etc. etc. etc.)
Go for a commercial solution if you really really need this: don't have any experience with those myself, however.

Resources