Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I've been searching online but all the top results on Google only lead me to Java. This is frustrating.
What I want to do is: make a program that listens to keyboard events, without being the active program. It has to work on at least windows 7, using C.
For example lets say I have myprogram.exe and other.exe. I want to be able to run both of them simultaneously, and have focus on other.exe, then press keys, and have myprogram.exe which runs on the side display which keys I pressed and log them.
If somebody has a link to a guide or information that explains what I should use to make this, that would be grand. If you can write up an explanation yourself that would be even better, but I don't mind going through documentations as long as they're relevant.
I've written games in C that listen to input from the active window, but I'm not sure how to poll events when the window isn't focused.
If you want to detect 'key press' events occurred in other processes, you should implement Global Hook. You can define a callback function for keyboard input events using SetWindowsHookEx().
Note that the callback function must be in a DLL in order to make it Global Hook.
So your myprogram.exe should link a dll implementing the hook. Then myprogram.exe would be able to detect any keyboard events on Windows.
Following is a good example with an explanation.
http://www.codeproject.com/Articles/1264/KeyBoard-Hooks
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 days ago.
Improve this question
I'm doing this project at work, and in my entire(short) career as a developer, I have never had to use anything related to time measurements in coding. However, I am now programming an electronic door that will lock in certain conditions. And I can't for the life of me figure out how to do it. Am I just supposed to use the time functions available? Because I'm pretty sure I can't use it considering it isn't present anywhere else in any project under my Team Leader.
Details:
there is an alarm system that has different states
when the alarm system IS NOT "LOCKED" (AlarmStatus != LOCKED) -> a timer starts that will count until 2 hours (I'm guessing I'll have to go for a WHILE LOOP here)
if AlarmStatus changes to LOCKED during these 2 hours, the timer will immediately reset
if the timer reaches 2 hours, the AlarmStatus will forcefully be transitioned to LOCKED and the timer will once again immediately reset
This is basically the gist of it, and I know it's not anything difficult, but I am unsure how to create that timer and reset it, and most importantly, how to measure the passage of time. Is there a way to do it without using functions from "time.h"?
Thanks all in advance for your time and responses!
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I am new at programming and was wondering if you could give me some advice as to how to make a alphanumeric character press do something using C? I would like to program a different function for each character pressed. Can anyone help me?
In your window procedure, you can react to WM_KEYDOWN messages. Your window will receive such a message when the user starts pressing down a key. When the user lets go of the key, you will receive a WM_KEYUP message.
See this tutorial on window messages for the basics on how to handle window messages.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I'm making a RPG game in batch, and the game looks bad, like the text layouts, does anyone have any design tips so my game looks more aesthetically pleasing?
I gave my students task to create I/O interactive, Terminal Based game, and some of students actually came back with fun results.
Use ASCII art. you can add different characters or scenes using ascii arts. you can find different arts on webpages like here and here. also you can convert your images to ASCII arts, that way you will be able to display any some images on Command Prompt
use ASCII Frames/borders for text and questions displays. you might need to resize frames by adding more characters, so it will fit your text.
use different colors to display different options, or underline good/bad events. I'm not sure about windows CMD but i tried on Unix and it works and looks pretty fun
Use Animations. Animate some lines by deleting line and redrawing/rewriting them. this way you will be able to receive Animation like results. its pretty easy, but you will need to store amount of characters outputted in line, so you will be able to clean exact amount of characters, otherwise you can clean full line
Here is example game that is fully created using ASCII art and it actually is pretty fun.
small examples from one of students i could find:
hope you'll find what you are looking for!
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I was making some games using Game Maker, but I would like to make simple games using C. I am a newb C programmer. When I code the output is always in the CMD Windows Console. I could make some simple games but always in the console, which is not very flexible (you can't animate without scrolling). When you run a more complex game, a complete new screen is created and I actually interact whit that screen.
So the question that i am having using C language is: How is this new screen being loaded? I think there is some windows API to create a new screen or something. By the way, in the old times, I mean DOS time, you just used a console but you could load a new screen where the game was played. How can you achieve this?
I would like some guideline to research the root. I just don't want to call library X or use SDL.
Thanks your your help.
Since you mention library X i assume you are on a Linux system. There are several different ways to archive your goal. If you would like to still use the console but with more graphics involved you could take a look at library ncurses ( http://www.gnu.org/software/ncurses/ ).
If you want to do more advanced graphics i recommend you to take a look here : How do you create a window in Linux with C++?
C programming dates back to 1970's, so you can think of creating games similar to that era.
The window or the new screen is loaded by few preprocessor directives which are already compiled and stored by the developers.
A new screen can be achieved by giving a few commands:
#include<stdio.h>
#include<conio.h>
void main()
{
local declarations;
And your program for the game;
getch();
}
What this basically do is the function getch(); which is stored in (conio.h) will open a new window and it will display
the output till it gets a value from the keyboard ie it displays the output till you press any key from the keyboard.
hope this answer helps you.
Creating new Windows can get pretty hairy (ie. the code can be complicated and difficult to read). I'll try to give a somewhat high-level overview, then link you to a good tutorial for loading a basic window.
You need to declare a couple of variables of types HWND and WNDCLASSEX, and call a bunch of Windows API functions to initialize the Window with some settings and whatnot.
Once this is done, you need to enter a loop that handles all the window interactions, usually with TranslateMessage and DispatchMessage inside the loop.
You also need to implement a callback procedure for handling Windows events such as mouse clicks, closing the window, etc. This is usually done in a LRESULT CALLBACK WndProcedure.
I've now thrown a bunch of new words and ideas around with little explanation; check out this tutorial for a full example of what I've just tried to explain.
http://www.functionx.com/win32/Lesson01c.htm
(EDIT: the link above is dead now, so here's a link to a cache of it from the Wayback Machine https://web.archive.org/web/20190203182520/http://www.functionx.com/win32/Lesson01c.htm)
Hope this helps!
Also - this is all assuming you're on Windows based on your comment about a Windows API (ie. windows.h). If you're on Linux, you'll need to use X.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'd like the buttons in my app to give feedback, as for example demonstrated here.
I'm wondering how I should structure my code. I want to be able to change the classes, the text and maybe disable them upon click. I guess a directive is the right fit, but the exact changes that will happen depend upon the button, and putting content or class names inside a controller or directive doesn't seem very right.
Right now i have a very generic directive that takes all options through additional attributes, but I wonder if someone can see a better way of doing it?
Always start with a very simple directive and extend with CSS classes. If you want to do a particular work well anything you can use a function of the controller. I think you made the right choice. Think to look angular UI for best practice : http://angular-ui.github.io
You can add event on each action:
// Create a new instance of ladda for the specified button
var l = Ladda.create( document.querySelector( '.my-button' ) );
// Start loading
l.start();
// Will display a progress bar for 50% of the button width
l.setProgress( 0.5 );
// Stop loading
l.stop();
// Toggle between loading/not loading states
l.toggle();
// Check the current state
l.isLoading();