How to record and run subsequently the input of a "broken keyboard"

edited December 2017 in Questions about Code

Hello guys! :) I inserted "keys broken" moments in my code. I need to record the keyboard input of those "broken-moments" and run them subsequently faster once the keyboard starts working again, in order to let the user realize he has regained control of the system. How can I do that? Thanks in advance!!

Answers

  • Sounds like a good concept. I have a feeling there are lots of things to be done here. However, you need to keep in mind we know nothing about how you want to do this. Also there are very obscure terms in your post:

    I inserted "keys broken" moments

    What is that?

    run them subsequently faster

    How? Under what conditions? Ok... maybe the question is when?

    once the keyboard starts working again

    I am sure this is related to the above two. It is better if you provide a mcve: https://stackoverflow.com/help/mcve

    Kf

  • I'm really sorry you're right. I'm a beginner and sometimes I forget the proper language. I'm doing a research about frustration in human-computer interaction and I'm using Snake as an investigation tool. So I've modified the game adding some bugs aiming to get the users frustrated while they're playing. I made the input of the keyboard stop working for a few seconds at determined slots of time. Afterwards, the keyboard starts working normally and the user keeps playing.

    I'd like to emulate what happens when the computer gets stuck and the user furiously keeps trying to open, for instance, a file: when the computer starts working again the file in question got open as many times as the user tried to open it during the stuck moment. So, in the matter of my case, I'm trying to build this behaviour when the user keeps pushing the keys, that are momentarily not operating, recording somehow which keys he presses, in what order and make them working with delay once the functions of the keyboard start working normally. This is part of the code, the one about the keyboard. I hope it's clearer!

      boolean keys_broken;
        int x, y;
        int time1 = 5000;
        int time2 = 8000;
        
        void setup() {
          size(600, 600);
          x = 100;
          y = 100;
          keys_broken = false;
        }
        
        void draw() {
          background(0);
          fill(0, 200, 0);
          ellipse(x, y, 20, 20);
        
          int curTimeMs = millis();
          if (curTimeMs > time1) {
            keys_broken = true;
          }
          if (curTimeMs > time2) {
            keys_broken = false;
          }
        }
        
        void keyPressed() {
          if (keys_broken) { 
            return;
          }
          if ( keyCode == LEFT ) { 
            x -= 5;
          }
          if ( keyCode == RIGHT ) {
            x += 5;
          }
          if ( keyCode == UP ) { 
            y -= 5;
          }
          if ( keyCode == DOWN ) { 
            y += 5;
          }
        }
    
  • edited December 2017 Answer ✓

    hello, it's good that you have the boolean keys_broken

    use it in keyPressed() to

    • either receive key as it is now OR

    • receive key to store in a new array of char that you define before setup():

      char[] charList;

    or use an arrayList

    in the moment keys_broken goes false, fire the array charList to your snake and then empty the array charList again

  • Thank you very much!

  • come back when you need more help

  • Actually, I'm in need again haha I'm going to open a new discussion if you can check it would be great otherwise have a nice weekend!

  • sure

    if you have a bigger project maybe you can upload it to github?

    you can also keep on writing here

  • I'm going to open a new discussion

    keep it here please.

  • edited December 2017

    koogs the new discussion would not be about the same problem! So I suppose it's better if I open another discussion but let me know if I have to do it differently!

  • The key question is, is it the same project that people helping you need to understand? If it is, and you need to explain about the timing and the snake and the keys all over again... then ask your follow-up question in this thread as a follow-up.

    Your separate question looks fine, but if at some point you need to share your complete code in each (a question about input, and about sound, etc.) then it is easier and less confusing to share it all in one place and update it as the conversation continues.

Sign In or Register to comment.