scan a barcode, play a sound on mac

attempt1:

clock_t start, diff, last, delaytime;

    start = clock();
    last = start;

diff = clock() - start;
    delaytime = diff - last;
    int startint = start * 1;
    int diffint = diff * 1;
    int clockint = clock() * 1;
    int lastint = last * 1;
    int delayint = delaytime * 1;
    //int msec = diff * 1000 / CLOCKS_PER_SEC;
    fprintf(logfile, "%s %d %s %d %s %d %s %d %s %d %s", "start:", startint, "clock:", clockint, "diff:", diffint, "last:", lastint, "delay:", delayint, "\n");

last = diff;

attempt2:

 double clo2;
double clo1;

 clo1 = clock();

clo2 = clock();
    double cdiff = clo2-clo1;

fprintf(logfile, "%s %f %s", "cdiff:", cdiff, "\n");

clo1 = clock();

got a timer working finally. had to really think about how I wanted to use this function:

 int gtod1_sec = t1.tv_sec;
    int gtod1_usec = t1.tv_usec;
    int gtod2_sec = t2.tv_sec;
    int gtod2_usec = t2.tv_usec;

    int diff_sec = gtod2_sec - gtod1_sec;
    int diff_usec = gtod2_usec - gtod1_usec;

    if (diff_usec < 0) {
        diff_sec = diff_sec - 1;
        diff_usec = 1000000 - diff_usec;
    }

    fprintf(logfile, "%s %d%s%d %s %d%s%d %s", "gettimeofday:", gtod2_sec, ".", gtod2_usec, "diff:", diff_sec, ".", diff_usec, "seconds\n");

Screen Shot 2017-04-06 at 5.04.14 PM

 

so what we want is:

if the key is a number, then start the timer.

if the next key is a number, reset the timer.

if the timer ever reaches 100,000 millionth seconds,  (1/10th of a second) that means it’s not a scan anymore, it’s someone typing, or the scan is done.  log the number.end the timer, and play a music file with that string’s filename.

log the number.

end the timer, and play a music file with that string’s filename.

and also:

[pop open the website (if it’s not the top one), and write the number there as well]

 

references:

http://www.bruji.com/cocoa/barcode.html – a codebase to scan a barcode in xcode on a mac

https://forum.openframeworks.cc/t/macos-10-12-sierra-xcode-8-quicktime-deprecation-workaround/24179/3 – a fix for xcode

https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/EventOverview/HandlingKeyEvents/HandlingKeyEvents.html – apple docs key event handeling

https://github.com/mosca1337/OSX-Keylogger – keylogger example 1

https://github.com/mosca1337/OSX-Keylogger – keylogger example 2

https://www.google.com/#q=xcode+simple+keylogger+example+code&* – key logger search results

https://github.com/caseyscarborough/keylogger – keylogger 3… this one works

http://stackoverflow.com/questions/8611815/determine-if-char-is-a-num-or-letter – determine if a character is a number in C

https://www.cs.bu.edu/teaching/cpp/string/array-vs-ptr/ – strings in C

http://stackoverflow.com/questions/2007219/osx-cocoa-how-to-check-which-window-is-in-focus – what window is in focus?

http://stackoverflow.com/questions/28289250/get-name-of-frontmost-window-in-os-x-with-accessibility-api

http://stackoverflow.com/questions/1981453/getting-the-main-window-of-an-app-via-an-nsrunningapplication-instance

https://developer.apple.com/library/content/samplecode/UIElementInspector/Introduction/Intro.html – code to inspect mac osx accessibility apit

http://blog.coriolis.ch/2008/03/04/bring-any-window-to-the-front/ – applescript to bring an application to the front

https://superuser.com/questions/263198/switch-between-google-chrome-tabs-using-applescript/1015721 – switch chrome tabs in applescript

http://stackoverflow.com/questions/18681553/xojo-launch-run-another-app-mac – launch another program from c

http://www.unix.com/programming/122190-c-program-execute-shell-script.html – system(“”) command in c to run a shell script/applescript

http://stackoverflow.com/questions/3736210/how-to-execute-a-shell-script-from-c-in-linux – a bash script in c

http://stackoverflow.com/questions/459691/best-timing-method-in-c – c timer

http://stackoverflow.com/questions/11850717/how-to-time-event-in-c – possibly investigate later

http://stackoverflow.com/questions/18783482/what-is-global-variable-in-c – global variable

https://cboard.cprogramming.com/cplusplus-programming/108637-time_t-now-milliseconds.html – another timer example

http://stackoverflow.com/questions/4264127/correct-format-specifier-for-double-in-printf – double in string format is %f

http://stackoverflow.com/questions/8558625/how-to-get-the-current-time-in-milliseconds-in-c-programming – clock not working for precise timer. look into gettimeofday()

http://stackoverflow.com/questions/2165726/how-do-i-record-timestamps-in-a-mac-os-x-c-program – gettimeofday() in mac?

http://www.mac-forums.com/os-x-development-and-darwin/139399-using-gettimeofday-compute-reaction-times.html – code example in c++

http://stackoverflow.com/questions/40967594/does-gettimeofday-on-macos-use-a-system-call – another code example of gettimeofday()

https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man2/gettimeofday.2.html – mac docs for gettimeofday()

http://stackoverflow.com/questions/1921539/using-boolean-values-in-c – no bool type in c, just use int 0 and 1.

http://timmurphy.org/2010/05/04/pthreads-in-c-a-minimal-working-example/ – create a thread in c

http://www.programmingsimplified.com/c/program/print-string – simple string tasks in c

http://stackoverflow.com/questions/632846/clearing-a-char-array-c – memset to clear

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s