# calc.awk BEGIN { MAXDISP=64; kbdstr= "Off C =0) && (button==1) ) { row = int((y-1200)/1200) col = int((x-200)/2000) rowcol=row*4+col if ( ( row >= 0 ) && ( row < 5 ) && ( col >= 0 ) && ( col < 4 ) ) { key_to_exe(rowcol) } } else if ( x == -2 ) { if ( button in a ) { key_to_exe( a[button] ) } } else if ( x == -4 ) { printf( "Rz %d %d\n", button, y );fflush(stdout); } else if ( x == -5 ) { printf( "Mv %d %d\n", button, y );fflush(stdout); } else if ( x == -98 ) { system( sprintf( "sleep %1.5f", 0.001*y ) ) } } } function key_to_exe( rowcol ) { if ( ( rowcol == 4) || ( rowcol == 5) || ( rowcol == 6) || ( rowcol == 8) || ( rowcol == 9) || ( rowcol == 10) || ( rowcol == 12) || ( rowcol == 13) || ( rowcol == 14) || ( rowcol == 16) || ( rowcol == 17) ) { if ( gfisnumberentering ) { #digits if ( length( gdisplaystr ) < ( MAXDISP - 1 ) ) { gdisplaystr = "" gdisplaystr "" akbdtext[rowcol+1] } } else { gdisplaystr = "" akbdtext[rowcol+1] gfisnumberentering = 1 } displaystr( gdisplaystr, 6052991 ) } else if ( rowcol == 0) { printf( "O 0 0 0\n" );fflush(stdout);close(stdout);exit(0) } else if ( rowcol == 1) { gdisplaystr="" displaystr( "0", 6052991 ) gfisnumberentering = 0 } else if ( rowcol == 2 ) { if ( length( gdisplaystr ) > 0 ) { if ( length( gdisplaystr ) == 1 ) { displaystr( "0", 6052991 ) } sub( /.$/, "", gdisplaystr ) if ( length( gdisplaystr ) > 0 ) { displaystr( gdisplaystr, 6052991 ) } } } else if ( rowcol == 18) { if ( length( gdisplaystr ) > 0 ) { #negate if ( gdisplaystr ~ /^-/ ) { sub( /^-/, "", gdisplaystr ) } else if ( gdisplaystrlen < ( MAXDISP - 1 ) ) { gdisplaystr = "-" gdisplaystr } displaystr( gdisplaystr, 6052991 ) } } else if ( ( rowcol == 3) || (rowcol == 7) || ( rowcol == 11) || ( rowcol == 15 ) ) { gbinop = akbdtext[rowcol+1]; gax = 0.0+gdisplaystr; gfisnumberentering = 0 } else if ( rowcol == 19 ) { if ( gfisnumberentering ) { gbx = 0.0+gdisplaystr; gfisnumberentering = 0 } if ( gbinop == "*" ) { gax *= gbx } else if ( gbinop == "/" ) { if ( gbx != 0 ) { gax /= gbx } else { gax = 99999999999 } } else if ( gbinop == "+" ) { gax += gbx } else if ( gbinop == "-" ) { gax -= gbx } gdisplaystr = sprintf( "%.16g", gax ) displaystr( gdisplaystr, 6052991 ) } } function displaystr( psz, color ) { printf( "F 0 16777215\nFR 0 0 0 9900 600\nF 0 %d\nR 0 100 100 9800 500\nR$ 0 9800 520\"%s\"\nZ \n" , color , (length(psz)?psz:"0") );fflush(stdout) }