How do I make s SIMPLE terminal game with real-time input on Linux? - input

I am looking a bit of simple code that will take whatever data comes from the keyboard at a given moment and let me check it for certain button presses. It doesn't matter what language it is in.
I am looking for a console solution, no GUI.

It sounds like you are looking for the curses library (you may also find an implementation as "ncurses", which is probably already installed on your system). This library powers most of the "full-screen" console programs that you might see on Linux.

Related

Applying Non-Standard Power Assertions & Creating Virtual HIDs

I've got a big ask here, but I am hoping someone might be able to help me. If there's another site you think this should be posted on, please let me know.
I'm the developer of the free app Amphetamine for macOS and I'm hoping to add a new feature to the app - keeping a Mac awake while in closed-display (clamshell) mode while not having a keyboard/mouse/power adapter/display connected to the Mac. I get requests to add this feature on an almost daily basis.
I've been working on a solution (and it's mostly ready) which uses a non-App Store helper app that must be download and installed separately. I could still go with that solution, but I want to explore one more option before pushing the separate app solution out to the world.
An Amphetamine user tipped me off that another app, AntiSleep can keep a Mac awake while in closed-display mode, while not meeting Apple's requirements. I've tested this claim, and it's true. After doing a bit of digging into how AntiSleep might be accomplishing this, I've come up with 2 possible theories so far (though there may be more to it):
In addition to the standard power assertion types, it looks like AntiSleep is using (a) private framework(s) to apply non-standard power assertions. The following non-standard power assertion types are active when AntiSleep is keeping a Mac awake: DenySystemSleep, UserIsActive, RequiresDisplayAudio, & InternalPreventDisplaySleep. I haven't been able to find much information on these power assertion types beyond what appears in IOPMLibPrivate.h. I'm not familiar at all with using private frameworks, but I assume I could theoretically add the IOPMLibPrivate header file to a project and then create these power assertion types. I understand that would likely result in an App Store review rejection for Amphetamine, of course. What about non-App Store apps? Would Apple notarize an app using this? Beyond that, could someone help me confirm that the only way to apply these non-standard power assertions is to use a private framework?
I suspect that AntiSleep may also be creating a virtual keyboard and mouse. Certainly, the idea of creating a virtual keyboard and mouse to get around Apple's requirement of having a keyboard and mouse connected to the Mac when using closed-display mode is an intriguing idea. After doing some searching, I found foohid. However, I ran into all kinds of errors trying to add and use the foohid files in a test project. Would someone be willing to take a look at the foohid project and help me understand whether it is theoretically possible to include this functionality in an App Store compatible app? I'm not asking for code help with that (yet). I'd just like some help determining whether it might be possible to do.
Thank you in advance for taking a look.
Would Apple notarize an app using this?
I haven't seen any issues with notarising code that uses private APIs. Currently, Apple only seems to use notarisation for scanning for inclusion of known malware.
Would someone be willing to take a look at the foohid project and help me understand whether it is theoretically possible to include this functionality in an App Store compatible app?
Taking a quick glance at the code of that project, it's clear it implements a kernel extension (kext). Those are not allowed on the App Store.
However, since macOS 10.15 Catalina, there's a new way to write HID drivers, using DriverKit. The idea is that the APIs are very similar to the kernel APIs, although I suspect it'll be a rewrite of the kext as a DriverKit driver, rather than a simple port.
DriverKit drivers are permitted to be included in App Store apps.
I don't know if a DriverKit based HID driver will solve your specific power management issue.
If you go with a DriverKit solution, this will only work on 10.15+.
I suspect that AntiSleep may also be creating a virtual keyboard and mouse.
I haven't looked at AntiSleep, but I do know that in addition to writing an outright HID driver, it's possible to generate HID events using user space APIs such as IOHIDPostEvent(). I don't know if those are allowed on the App Store, but as far as I'm aware, IOKitLib is generally fine.
It's possible you might be able to implement your virtual input device using those.

wxWidgets GUI + Console/Emulating a Console (wxTextCtrl?)

I have a wxWidgets GUI program, and I would like to have a standard console window attached to it for stdout/etc. to go to.
If someone knows how to do this (a GUI application and and a console window) that would be splendid. However, from looking around, I suspect this isn't directly possible.
Based on this similar thread, I got the impression that this could be simulated with a wxTextCtrl in a separate wxFrame. If this is a good way to do it, are there examples of it being done anywhere? Are there other ways to do this?
EDIT: I am looking to either have (or at least emulate as closely as possible) a console window--so, black background, white characters with fixed-width font, etc.
You can redirect e.g. std::cout to wxTextCtrl using wxStreamToTextRedirector but it doesn't really replace a real console under Windows or a PTY under Unix because only the text output via std::cout will be redirected but not anything printed using printf() or any other functions. If you need the latter, you need to do something platform-specific and in this case you should tell which platform(s) are you using and what exactly do you need to do.
I recomend 'upgrading' from stdout to the wxWidgets logging classes, which are way more flexible. Here is an overview.

Is it possible to record screen with Titanium / Appcelerator?

We're in process of developing a desktop application which needs to record user's screen once he clicks a button. I read a tutorial about Adobe AIR, which says it is easy to do with AIR: http://www.adobe.com/devnet/air/flex/articles/air_screenrecording.html
But our preference is Titanium as we've explored it a little bit. So I want to know is that even possible? If yes, how can we get started with?
There's also an interesting solution which uses Java applet for recording, as demonstrated here: http://www.screencast-o-matic.com/create?step=info&sid=default&itype=choose
But again, we're not sure about JAVA and would like to know how can it be done? or if its even possible to run a JAVA applet in Titanium?
When you say "record screen", I'm assuming you mean video. Correct?
The only way to do this in Titanium Desktop right now is to take a bunch of screenshots and string them together (encoding would probably need to be done server-side).
Depending on how long your videos need to be, this probably won't work for you. I'm also not confident in how quickly you could capture screenshots, and if it would have a high enough frame rate to be usable.
Past that, a module could be developed for Desktop to support some native APIs to record video. That's not something I see on the horizon, though.
I hope this helps, albiet a rather dismal answer. -Dawson

How to simulate user input in objective-c?

On windows, and with c#, I was able to capture another window's "screen", use that for processing, and then send user input events to that window. (which were generated by the program).
I would like to do the same with objective-c and within Mac OS X. So! Any resources or even a name for what I'm trying to do would be great. It's very frustrating to try and find information on this when the only ways i can think to phrase my searches are too ambiguous.
Thanks!
EDIT: As a specific example, there might be a particular game that I want to make an AI for. In that case I would need to be able to send mouse and keyboard events to the game.
If you're looking to do automated user interface testing, look at Squish, eggPlant, expect and OS X Accessibility. If you're looking to programmatically control another program, use scripting (if you wrote the program to control, add scripting support; otherwise, see what scripting support the program offers), or try Automator.

How to make a library for the webcam?

I'm learning Factor and I thought it would be great to have a small program to capture images from the webcam that comes with my mac pro. I know every webcam will be very different but sounds like something I should be able to do. I want to create a library with support for Mac, Linux and Windows. The problem is that I'm not sure where to start.
Factor-based answers are welcome but I'm looking for the language agnostic solutio. When I google for it, all I get is programs that capture images. I want to learn how to interact (in the 3 big operative systems) with the drivers I guess.
I think the only clue I have is the ioctl wiki page. How would you start such a project? What kind of google keywords would you use? Books?
It's not clear if you want to write a driver for your particular webcam or a library that makes talking to the existing driver easier.
If you want to write a driver for your webcam, you probably want to investigate libusb for Mac and Linux and libusb-win32 for Windows. You would need to understand the protocol that your webcam talks, though. You could probably read the source code for the existing Linux driver (assuming there is one, which is pretty likely).
As for Google search terms, you might try "video capture" and maybe looking for Python/Ruby etc. code or Open Source programs will get you code you can look at to see how to do what you want to do.
Perhaps if you describe in a little more details what you're trying to accomplish someone could give you better suggestions.