// press all supported keys // text is a string which contains the key identifiers eg. "KEY_CTRL KEY_C" for Ctrl-C void setKeyValues(char* text) { char tmptxt[MAX_KEYSTRING_LEN]; // for parsing keystrings char * acttoken; int modifiers=0; strcpy(tmptxt, text); acttoken = strtok(tmptxt," "); while (acttoken) { int kc=getKeycode(acttoken); if (kc) updateKey(kc); acttoken = strtok(NULL," "); } }
void sendToKeyboard(char * writeKeystring) { char tmp[MAX_KEYSTRING_LEN]; char * p1, *p2, *p3; strcpy (tmp,writeKeystring); p1=tmp; p2=strstr(p1,"KEY_"); while (p2) { p3=p2; while ((*p3!=' ') && (*p3)) p3++; if (*p3) {*p3=0; p3++;} int kc= getKeycode(p2); *p2=0; if (p1!=p2) writeTranslatedKeys (p1); if (kc) Keyboard.write(kc); p1=p3; if (*p1) p2=strstr(p1,"KEY_"); else p2=0; } writeTranslatedKeys(p1); }
int painter(string args) { if (streql(splitArg(args, 1), "-H")) { print("\nPainter is a simple drawing app for Q OS",red); print("\nTo use it, type 'painter' on the command line.",red); print("\nUse the arrow keys to draw lines on your screen.",red); print("\nPress the spacebar to reset your drawing.",red); print("\nPress X to change the X location of your pen and Y to change the Y location.",red); } else { // Run the setup function for painter resetPainter(); bool isDrawing = true; #define GET_PAINT_COLOR isDrawing ? 0x00 : screen_color // Begin the actual painter program while (true) { if (paintX < 1) { paintX = 1; } else if (paintX > 78) { paintX = 78; } if (paintY < 5) { paintY = 5; } else if (paintY > 23) { paintY = 23; } printAt("*",0xDD,paintX,paintY); printStatus(isDrawing); int key = getKeycode() / KC_MAGIC_VAL; switch (key) { case 1: // Escape Pressed clearScreen(); return 0; case 72: // Up Arrow Pressed printAt(" ", GET_PAINT_COLOR, paintX, paintY); paintY--; break; case 80: // Down Arrow Pressed printAt(" ", GET_PAINT_COLOR, paintX, paintY); paintY++; break; case 75: // Left Arrow Pressed printAt(" ", GET_PAINT_COLOR, paintX, paintY); paintX--; break; case 77: // Right Arrow Pressed printAt(" ", GET_PAINT_COLOR, paintX, paintY); paintX++; break; case 57: // Spacebar Pressed resetPainter(); break; case 0x2E: // C pressed isDrawing = true; break; case 0x12: // E pressed isDrawing = false; break; case -82: // X Released printAt(" ",screen_color,paintX,paintY); drawFrame(header_background, 0, 0, 80, 4); printAt("What X Posiiton do you want to move the pen to?\r\n", header_foreground, 1, 1); cursorX = 1; cursorY = 2; // we need to make the text below when input show in a blue on aqua font... paintX = stoi(readstr()); painterIntro(); break; case -106: // Y Pressed printAt(" ",screen_color,paintX,paintY); drawFrame(header_background, 0, 0, 80, 4); printAt("What Y Posiiton do you want to move the pen to?\r\n", header_foreground, 1, 1); cursorX = 1; cursorY = 2; // we need to make the text below when input show in a blue on aqua font... paintY = stoi(readstr()); painterIntro(); break; default: break; } } } return 0; }
string initWriter() { string vidmem = (string) 0xb8000; char oldmem[strlen(vidmem)]; strcpy(oldmem, vidmem); paintScreen(screen_color); drawFrame(header_background, 0, 0, 80, 4); printAt("Q OS Text Editor\r\n", header_foreground, 1, 1); printAt("Simple Text Editor built for Q OS by Raph Hennessy & Plankp T",desc_foreground,1,2); drawBorder(screen_background, 0, 4, 80, sh - 1); cursorY = 5; cursorX = 1; updateCursor(); bool inCmdMode = true; uint16 curX = 1, curY = 5; uint32 index = 0; strbuilder_t data = strbuilder_init(); int k; while(true) { cursorX = curX % sw; cursorY = curY; updateCursor(); cursorBoundsCheck(&curX, &curY, &index); printStatus(curX, curY, inCmdMode); if(inCmdMode) { k = waitUntilKey(7, 0x10 /*Q*/, 0x17 /*I*/, 0x18 /*O*/, 0x3A /*<CAPS>*/, 0x23 /*H*/, 0x26 /*L*/, 0x2D /*X*/); switch(k) { case 0x10: goto end; case 0x17: inCmdMode = false; break; case 0x18: appendln(&data, &curX, &curY, &index); inCmdMode = false; break; case 0x23: moveCursorLeft(&curX, &curY, &index); break; case 0x26: moveCursorRight(&curX, &curY, &index); break; case 0x2D: deleteCharAt(&curX, &curY, &index, &data); break; } } else { k = getKeycode() / KC_MAGIC_VAL; char charInput = ' '; switch(k) { case 0x01: inCmdMode = true; break; case 0x1C: cursorBoundsCheck(&curX, &curY, &index); appendln(&data, &curX, &curY, &index); break; case 0x48: curY--; curX = 1; cursorBoundsCheck(&curX, &curY, &index); break; case 0x4B: moveCursorLeft(&curX, &curY, &index); break; case 0x4D: moveCursorRight(&curX, &curY, &index); break; case 0x50: curY++; curX = 1; cursorBoundsCheck(&curX, &curY, &index); break; case 0x0E: deleteCharAt(&curX, &curY, &index, &data); break; default: if(k < 59 && k > 0) { charInput = retCorrespChar(kbShiftChars[k], kbLowerChars[k]); if(charInput == 0) { break; } insertCharAt(&curX, &curY, &index, &data, charInput); } break; } } } end: // Sorry for the mom spaghetti code // Must be last line (before any prints) strcpy(vidmem, oldmem); string msg = strbuilder_tostr(data); if(msg == NULL) { msg = ""; } strbuilder_destroy(&data); cursorX = 1; cursorY = 5; print(msg, black); return msg; }