Python keylogger with keystroke durations - keystroke

I was searching a program which detects my keystrokes with the stoke's duration also. I imagine the output like this:
W : 3 sec
A : 2.4 sec
etc..
Can someone help me how to create a program like this in python? I couldn't even start it.

Related

Script to run multiple OpenCv programs in Windows

I like to run several OpenCV programs one by one in a DO Loop. After searching the web , think for this case need to use batch file. Is that right?
I have 10 OpenCV programs. Each program detect specific features in the image with some successful rate. So, for any image(with many features to be detected) I wonna run first the program with the highest successful rate. If this failed to detect feature then run next one with second highest rate and so on. So, for example program1 is the one with the highest rate, then come program2 and so on
So I have output for each of the 10 OpenCv programs. Let we say output 1 if detect the feature (or the object) in the image and 0 if it failed. So the script should start the program 1 first and if the outcome of this program is 1 then will do something (not important at the moment what), but if the outcome is 0 then need to start the program 2. Same for program 2. If the output of program 2 is 1 then do something (also not important what), but if the output is 0 (means did not detect the object) then run the next program (means program3)
Any idea how it should look like?
I have thinking of something like this , but not sure about the control
#ECHO OFF
START program1.exe
ECHO Timeout waiting for program1.exe to start
GOTO :EOF
:: if the output of program1.exe is 1 then do somethig, else if the output of program1.exe is 0 run the program2.exe (I dont know how this part should be in the script)
:: not sure for control
:startnext
program2.exe
:: or START program2.exe

make a C program relaunch itself after x seconds

Is it possible to make a program written in C to stop and then relaunch itself after x seconds In windows ?? And if yes, how to make it happen ??
You can accomplish that goal by having your program launch a second program, whose only function is to wait a while and then launch your first program again. In pseudocode, the idea would be:
Program A:
Do whatever the program is supposed to do
Launch program B
exit.
Program B:
Wait predetermined time
Launch program A
exit.
I hope this answers your question adequately.
The way I do this kind of thing is with a command-line option 'startDelay=xx'.
If there is no such command, my app just starts up as normal. If there is, its first action , before attempting to open any files, DB, construct GUI, start threads, start server etc. is to sleep for 'xx' seconds.
If my app needs to restart itself, it copies its own command-line, adds the 'startDelay=xx' to it and launches a new copy of itself, which then immediately sleeps. The original then has plenty of time to shut down normally before the new copy starts the bulk of its run-up.
No need for any other app or Windows scheduler and/or cron crap:)

Gstreamer- Duration query error on mp3

I am working on a simple application using Gstreamer on C, that involves playing a song and show some info about it on terminal. Thta info includes the total length of the song in seconds. As usual, I used the function gst_element_query_duration to get this data. The thing is, when I run my program, sometimes it shows the right time on screen, but then I run it again and the total time showed is about 6 seconds less. Because is just a simple trial application, I am using playbin as the general bin for reproduction, so I tried with different file extensions and it seems this only happens with mp3 files. Have anyone ever experienced this? Any ideas on how to fix it?
MP3 has the problem that there is no duration stored inside the file (usually). With constant bitrate files you can simply check the bitrate and the file size, but for variable bitrate files you can only do an approximation based on that. Your problem is probably exactly that.
The only way to know the exact duration of a variable bitrate MP3 file without header information with the duration (see Xing header) is to parse the file until the end and count the exact duration. With playbin you should get the accurate duration at the end of the file.

how to pause and play sound

Hey all I want to play a sound. I issue a c command and it plays the sound, then the user presses a key, let's say "h" and then the sound stops for 5 seconds, and returns after 5 seconds. What c command can i use to do this? I thought mci send string might work, but I'm not sure.
Play Sound was my go to but it doesn't have this functionality.
any code suggestions?
I assume you are using Windows
Use the waveOutPause() to pause the audio.
Use Sleep(5000);
Use the waveOutRestart() to start the audio from where it paused.
See also: waveOutPause MSDN documentation

Average execution time

is there any nice GNU way how to measure average (worst case, best case) execution time of some command line program? I have image filter, unspecified amount of pictures, filtering them using for-loop in bash. So far I am using time, but I can't find a way how to get some statistics.
You can send the output of time to some file, and then "work" that file
echo "some info" >> timefile.txt
time ( ./yourprog parm1 parm2 ) 2>> timefile.txt
There's an interesting Perl program called dumbbench that's essentially a wrapper around the time command. It runs your program a number of times, throws away outliers, then calculates some statistics.
The author has a couple of articles (here and here) outlining a) why benchmarking sucks, and b) what kind of pretty graphs you can make to make your benchmarking numbers suck a little less.
You're on the right track with time. It's what I use to preform small code execution analyses.
I then use python to collect the statistics by reading the output of time. In order to increase accuracy, I typically do the trial 10 - 1000 times, depending on how long each process takes.
I'm not familiar with any pre-installed GNU application that does this sort of analysis.
#!/bin/bash
for i in {1..100}
do
env time --append -o time_output.txt ./test_program --arguments-to-test-program
done
exit
If you find that the {1..100} syntax doesn't work for you then you should have a look at the seq command.
I used the env time to execute the time program rather than the shell's built in command, which does not take all of the arguments that the time program takes. The time program also takes other arguments to alter the format of it's output, which you will probably want to use to make the data easier to process by another program. The -p (--portability) argument makes it output in the POSIX format (like BASH's builtin time does), but using the -f option you can get more control. man 1 time for more info.
After you have gathered your data a simple perl or python script can easily parse and analyze your timing data.
You should consider whether to time the outer loop and divide by the repetitions rather than timing each iteration separately. If you're worried about discarding the high and low, just do a few more iterations to drown them out.
time for i in {1..1000}
do
something
done
You can capture the output from time in a variable:
foo=$( { time {
echo "stdout test message demo"
for i in {1..30}
do
something
done
echo "stderr test message demo" >&2
} 1>&3 2>&4; } 2>&1 )
and do some fake math:
foo=${foo/.} # "divide" by ...
echo "0.00${foo/#0}" # ... 1000
Or just use bc:
echo "scale=8; $foo/1000" | bc

Resources