// EvntRec 1.3 /* by Patrick Lorch */ // This event recorder records key strokes int brd[18],nkey,tme; // The board etc. string lastkey; // The keys /* Change these to correspond to behaviors or grid locations. 1-9 are events with duration 10-18 are 1time events or grid locations */ /* keys should all be same # chars including spaces */ string keys[18]={" 1"," 2"," 3"," 4", " 5"," 6"," 7"," 8"," 9","10","11", "12","13","14","15","16","17","18"}; drawx(int x, int y) { // Draw an 'x' at grid location (x,y) x = x * 40 + 20; y = y * 20 + 27; line(1, x+3, y+3, x+37, y+18); line(1, x+3, y+18, x+37, y+3); } erasex(int x, int y) { // Erase the 'x' at grid location (x,y) x = x * 40 + 20; y = y * 20 + 27; line(0, x+3, y+3, x+37, y+18); line(0, x+3, y+18, x+37, y+3); } tap() { int x, y; while(1) { // Wait for a pen up event waitp(); tme=time(2); beep(1); x = penx(); y = peny(); // Did the user tap outside the grid? if (x<20 || x>140 || y<27 || y>147) return -1; // Get grid coordinates x = (x-20)/40; y = (y-27)/20; nkey=x+3*y; lastkey=keys[nkey]; if ((nkey)<9) // keys 0-10 if(brd[nkey] == 0) { // mark the space as used brd[nkey] = 1; drawx(x,y); return 1; } else { // unmark the space brd[nkey] = 0; erasex(x,y); return 2; } else { brd[nkey]++; return 3; } return 0; } // end while } main() { int test,i,j,k=0; string fname; clear(); puts("Event recorder\n\nTap outside the grid to exit.\nTap anywhere to start...\n\n"); puts(" 1-9 are events with duration\n 10-18 are 1 time events or grid locations \n"); wait(); graph_on(); title("Event recorder"); // Draw grid line(1,60,27,60,147); line(1,100,27,100,147); line(1,20,47,140,47); line(1,20,67,140,67); line(1,20,87,140,87); line(1,20,89,140,89); line(1,20,107,140,107); line(1,20,127,140,127); // Draw the gray border frame(2, 20, 27, 140, 147, 0); // Draw text into keys for(j=33;j<134;j=j+20) for(i=23;i<104;i=i+40) text(i,j,keys[k++]); // get datafile name if((fname=getsd("Enter data filename: ", "ERdata"+date(1)+"_"+ time(2))) == "") exit(); // open new memo & name it if(!mmnew()){ puts("Could not create file\n"); exit(); } mmputs(fname+"\n"); // mmputs(date(1)+"\n"); mmputs("eventID, time, cat\n"); // Record events while (1) { test=tap(); if(test==-1) return;// Exit switch (test) { case 1: mmputs(lastkey+ ","+ tme+","+"start\n"); break; case 2: mmputs(lastkey+","+ tme+","+"end\n"); break; case 3: mmputs(lastkey+","+ tme+","+"event\n"); break; case 0: break; default: break; } // end switch text(13,13,"lastkey = " + lastkey); } mmclose(); }