keyboard.play function not working correctly





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







-1















When calling the function with list of events it does nothing.



I've tried to save it to file or somehow share the variable but nothing has worked so far.



This is record.py which records pressed keys and saves them to file



import keyboard
import pickle

with open('keys.txt','wb') as f:
pickle.dump(keyboard.record(until='*'),f)


And here is script.py which loads pressed keys from file and presses them again



import keyboard
import pickle

with open('keys.txt','rb') as f:
keyboard.play(pickle.load(f))


It doesn't show up any errors, but it does nothing - it should type what was saved in the file but it doesn't.










share|improve this question

























  • Do you understand what open('file.txt', 'wb')'s 'wb' stands for? This makes it a binary file. You can't simply write bytes to a file and expect text from it. Note pickle just makes an object into a binary stream (bytes object) and can return an object from that stream again.

    – GeeTransit
    Jan 3 at 20:31













  • I needed to save list of events into file and this is the only way I found of doing it

    – MartinqooN
    Jan 3 at 20:33











  • The pickle.load(f) does its job, it loads correct list, but the function somehow does nothing.

    – MartinqooN
    Jan 3 at 20:33











  • Which function 'does nothing'?

    – GeeTransit
    Jan 3 at 20:35











  • keyboard.play() doesn't press or do anything, it types nothing. If I change the code to just write out the list made by pickle.load(f), it writes the correct list - list full of keyboard events, so there's no mistake in that

    – MartinqooN
    Jan 3 at 20:37




















-1















When calling the function with list of events it does nothing.



I've tried to save it to file or somehow share the variable but nothing has worked so far.



This is record.py which records pressed keys and saves them to file



import keyboard
import pickle

with open('keys.txt','wb') as f:
pickle.dump(keyboard.record(until='*'),f)


And here is script.py which loads pressed keys from file and presses them again



import keyboard
import pickle

with open('keys.txt','rb') as f:
keyboard.play(pickle.load(f))


It doesn't show up any errors, but it does nothing - it should type what was saved in the file but it doesn't.










share|improve this question

























  • Do you understand what open('file.txt', 'wb')'s 'wb' stands for? This makes it a binary file. You can't simply write bytes to a file and expect text from it. Note pickle just makes an object into a binary stream (bytes object) and can return an object from that stream again.

    – GeeTransit
    Jan 3 at 20:31













  • I needed to save list of events into file and this is the only way I found of doing it

    – MartinqooN
    Jan 3 at 20:33











  • The pickle.load(f) does its job, it loads correct list, but the function somehow does nothing.

    – MartinqooN
    Jan 3 at 20:33











  • Which function 'does nothing'?

    – GeeTransit
    Jan 3 at 20:35











  • keyboard.play() doesn't press or do anything, it types nothing. If I change the code to just write out the list made by pickle.load(f), it writes the correct list - list full of keyboard events, so there's no mistake in that

    – MartinqooN
    Jan 3 at 20:37
















-1












-1








-1








When calling the function with list of events it does nothing.



I've tried to save it to file or somehow share the variable but nothing has worked so far.



This is record.py which records pressed keys and saves them to file



import keyboard
import pickle

with open('keys.txt','wb') as f:
pickle.dump(keyboard.record(until='*'),f)


And here is script.py which loads pressed keys from file and presses them again



import keyboard
import pickle

with open('keys.txt','rb') as f:
keyboard.play(pickle.load(f))


It doesn't show up any errors, but it does nothing - it should type what was saved in the file but it doesn't.










share|improve this question
















When calling the function with list of events it does nothing.



I've tried to save it to file or somehow share the variable but nothing has worked so far.



This is record.py which records pressed keys and saves them to file



import keyboard
import pickle

with open('keys.txt','wb') as f:
pickle.dump(keyboard.record(until='*'),f)


And here is script.py which loads pressed keys from file and presses them again



import keyboard
import pickle

with open('keys.txt','rb') as f:
keyboard.play(pickle.load(f))


It doesn't show up any errors, but it does nothing - it should type what was saved in the file but it doesn't.







python python-3.x pickle keyboard-events






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 21:37







MartinqooN

















asked Jan 3 at 20:26









MartinqooNMartinqooN

12




12













  • Do you understand what open('file.txt', 'wb')'s 'wb' stands for? This makes it a binary file. You can't simply write bytes to a file and expect text from it. Note pickle just makes an object into a binary stream (bytes object) and can return an object from that stream again.

    – GeeTransit
    Jan 3 at 20:31













  • I needed to save list of events into file and this is the only way I found of doing it

    – MartinqooN
    Jan 3 at 20:33











  • The pickle.load(f) does its job, it loads correct list, but the function somehow does nothing.

    – MartinqooN
    Jan 3 at 20:33











  • Which function 'does nothing'?

    – GeeTransit
    Jan 3 at 20:35











  • keyboard.play() doesn't press or do anything, it types nothing. If I change the code to just write out the list made by pickle.load(f), it writes the correct list - list full of keyboard events, so there's no mistake in that

    – MartinqooN
    Jan 3 at 20:37





















  • Do you understand what open('file.txt', 'wb')'s 'wb' stands for? This makes it a binary file. You can't simply write bytes to a file and expect text from it. Note pickle just makes an object into a binary stream (bytes object) and can return an object from that stream again.

    – GeeTransit
    Jan 3 at 20:31













  • I needed to save list of events into file and this is the only way I found of doing it

    – MartinqooN
    Jan 3 at 20:33











  • The pickle.load(f) does its job, it loads correct list, but the function somehow does nothing.

    – MartinqooN
    Jan 3 at 20:33











  • Which function 'does nothing'?

    – GeeTransit
    Jan 3 at 20:35











  • keyboard.play() doesn't press or do anything, it types nothing. If I change the code to just write out the list made by pickle.load(f), it writes the correct list - list full of keyboard events, so there's no mistake in that

    – MartinqooN
    Jan 3 at 20:37



















Do you understand what open('file.txt', 'wb')'s 'wb' stands for? This makes it a binary file. You can't simply write bytes to a file and expect text from it. Note pickle just makes an object into a binary stream (bytes object) and can return an object from that stream again.

– GeeTransit
Jan 3 at 20:31







Do you understand what open('file.txt', 'wb')'s 'wb' stands for? This makes it a binary file. You can't simply write bytes to a file and expect text from it. Note pickle just makes an object into a binary stream (bytes object) and can return an object from that stream again.

– GeeTransit
Jan 3 at 20:31















I needed to save list of events into file and this is the only way I found of doing it

– MartinqooN
Jan 3 at 20:33





I needed to save list of events into file and this is the only way I found of doing it

– MartinqooN
Jan 3 at 20:33













The pickle.load(f) does its job, it loads correct list, but the function somehow does nothing.

– MartinqooN
Jan 3 at 20:33





The pickle.load(f) does its job, it loads correct list, but the function somehow does nothing.

– MartinqooN
Jan 3 at 20:33













Which function 'does nothing'?

– GeeTransit
Jan 3 at 20:35





Which function 'does nothing'?

– GeeTransit
Jan 3 at 20:35













keyboard.play() doesn't press or do anything, it types nothing. If I change the code to just write out the list made by pickle.load(f), it writes the correct list - list full of keyboard events, so there's no mistake in that

– MartinqooN
Jan 3 at 20:37







keyboard.play() doesn't press or do anything, it types nothing. If I change the code to just write out the list made by pickle.load(f), it writes the correct list - list full of keyboard events, so there's no mistake in that

– MartinqooN
Jan 3 at 20:37














2 Answers
2






active

oldest

votes


















0














Try to set the events from keyboard into a list first.



record.py



import keyboard as k
import pickle as p
events = k.record(until = '*')
with open('events.txt', mode = 'wb') as file:
p.dump(events, file)


script.py



import keyboard as k
import pickle as p
with open('events.txt', mode = 'rb') as file:
events = p.load(file)
# end with
k.replay(events)





share|improve this answer


























  • It still doesn't type or do anything unfortunately

    – MartinqooN
    Jan 3 at 21:10











  • Hmm... Are you running this with IDLE?

    – GeeTransit
    Jan 3 at 21:10











  • Tried within IDLE and then within other app (google search typing) and it didn't type anything. Does it work for you?

    – MartinqooN
    Jan 3 at 21:12











  • It does... Did keyboard install properly?

    – GeeTransit
    Jan 3 at 21:12











  • Tried uninstalling keyboard module and reinstalling and still doesn't do anything

    – MartinqooN
    Jan 3 at 21:16





















0














I solved the problem by putting "useless" functions, that don't really achieve anything. The record.py stays the same, I changed the script.py just like this:



import keyboard
import pickle

keyboard.start_recording()
keyboard.stop_recording()

with open('keys.txt','rb') as f:
keyboard.play(pickle.load(f))





share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54029314%2fkeyboard-play-function-not-working-correctly%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Try to set the events from keyboard into a list first.



    record.py



    import keyboard as k
    import pickle as p
    events = k.record(until = '*')
    with open('events.txt', mode = 'wb') as file:
    p.dump(events, file)


    script.py



    import keyboard as k
    import pickle as p
    with open('events.txt', mode = 'rb') as file:
    events = p.load(file)
    # end with
    k.replay(events)





    share|improve this answer


























    • It still doesn't type or do anything unfortunately

      – MartinqooN
      Jan 3 at 21:10











    • Hmm... Are you running this with IDLE?

      – GeeTransit
      Jan 3 at 21:10











    • Tried within IDLE and then within other app (google search typing) and it didn't type anything. Does it work for you?

      – MartinqooN
      Jan 3 at 21:12











    • It does... Did keyboard install properly?

      – GeeTransit
      Jan 3 at 21:12











    • Tried uninstalling keyboard module and reinstalling and still doesn't do anything

      – MartinqooN
      Jan 3 at 21:16


















    0














    Try to set the events from keyboard into a list first.



    record.py



    import keyboard as k
    import pickle as p
    events = k.record(until = '*')
    with open('events.txt', mode = 'wb') as file:
    p.dump(events, file)


    script.py



    import keyboard as k
    import pickle as p
    with open('events.txt', mode = 'rb') as file:
    events = p.load(file)
    # end with
    k.replay(events)





    share|improve this answer


























    • It still doesn't type or do anything unfortunately

      – MartinqooN
      Jan 3 at 21:10











    • Hmm... Are you running this with IDLE?

      – GeeTransit
      Jan 3 at 21:10











    • Tried within IDLE and then within other app (google search typing) and it didn't type anything. Does it work for you?

      – MartinqooN
      Jan 3 at 21:12











    • It does... Did keyboard install properly?

      – GeeTransit
      Jan 3 at 21:12











    • Tried uninstalling keyboard module and reinstalling and still doesn't do anything

      – MartinqooN
      Jan 3 at 21:16
















    0












    0








    0







    Try to set the events from keyboard into a list first.



    record.py



    import keyboard as k
    import pickle as p
    events = k.record(until = '*')
    with open('events.txt', mode = 'wb') as file:
    p.dump(events, file)


    script.py



    import keyboard as k
    import pickle as p
    with open('events.txt', mode = 'rb') as file:
    events = p.load(file)
    # end with
    k.replay(events)





    share|improve this answer















    Try to set the events from keyboard into a list first.



    record.py



    import keyboard as k
    import pickle as p
    events = k.record(until = '*')
    with open('events.txt', mode = 'wb') as file:
    p.dump(events, file)


    script.py



    import keyboard as k
    import pickle as p
    with open('events.txt', mode = 'rb') as file:
    events = p.load(file)
    # end with
    k.replay(events)






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jan 3 at 21:11

























    answered Jan 3 at 21:07









    GeeTransitGeeTransit

    694316




    694316













    • It still doesn't type or do anything unfortunately

      – MartinqooN
      Jan 3 at 21:10











    • Hmm... Are you running this with IDLE?

      – GeeTransit
      Jan 3 at 21:10











    • Tried within IDLE and then within other app (google search typing) and it didn't type anything. Does it work for you?

      – MartinqooN
      Jan 3 at 21:12











    • It does... Did keyboard install properly?

      – GeeTransit
      Jan 3 at 21:12











    • Tried uninstalling keyboard module and reinstalling and still doesn't do anything

      – MartinqooN
      Jan 3 at 21:16





















    • It still doesn't type or do anything unfortunately

      – MartinqooN
      Jan 3 at 21:10











    • Hmm... Are you running this with IDLE?

      – GeeTransit
      Jan 3 at 21:10











    • Tried within IDLE and then within other app (google search typing) and it didn't type anything. Does it work for you?

      – MartinqooN
      Jan 3 at 21:12











    • It does... Did keyboard install properly?

      – GeeTransit
      Jan 3 at 21:12











    • Tried uninstalling keyboard module and reinstalling and still doesn't do anything

      – MartinqooN
      Jan 3 at 21:16



















    It still doesn't type or do anything unfortunately

    – MartinqooN
    Jan 3 at 21:10





    It still doesn't type or do anything unfortunately

    – MartinqooN
    Jan 3 at 21:10













    Hmm... Are you running this with IDLE?

    – GeeTransit
    Jan 3 at 21:10





    Hmm... Are you running this with IDLE?

    – GeeTransit
    Jan 3 at 21:10













    Tried within IDLE and then within other app (google search typing) and it didn't type anything. Does it work for you?

    – MartinqooN
    Jan 3 at 21:12





    Tried within IDLE and then within other app (google search typing) and it didn't type anything. Does it work for you?

    – MartinqooN
    Jan 3 at 21:12













    It does... Did keyboard install properly?

    – GeeTransit
    Jan 3 at 21:12





    It does... Did keyboard install properly?

    – GeeTransit
    Jan 3 at 21:12













    Tried uninstalling keyboard module and reinstalling and still doesn't do anything

    – MartinqooN
    Jan 3 at 21:16







    Tried uninstalling keyboard module and reinstalling and still doesn't do anything

    – MartinqooN
    Jan 3 at 21:16















    0














    I solved the problem by putting "useless" functions, that don't really achieve anything. The record.py stays the same, I changed the script.py just like this:



    import keyboard
    import pickle

    keyboard.start_recording()
    keyboard.stop_recording()

    with open('keys.txt','rb') as f:
    keyboard.play(pickle.load(f))





    share|improve this answer




























      0














      I solved the problem by putting "useless" functions, that don't really achieve anything. The record.py stays the same, I changed the script.py just like this:



      import keyboard
      import pickle

      keyboard.start_recording()
      keyboard.stop_recording()

      with open('keys.txt','rb') as f:
      keyboard.play(pickle.load(f))





      share|improve this answer


























        0












        0








        0







        I solved the problem by putting "useless" functions, that don't really achieve anything. The record.py stays the same, I changed the script.py just like this:



        import keyboard
        import pickle

        keyboard.start_recording()
        keyboard.stop_recording()

        with open('keys.txt','rb') as f:
        keyboard.play(pickle.load(f))





        share|improve this answer













        I solved the problem by putting "useless" functions, that don't really achieve anything. The record.py stays the same, I changed the script.py just like this:



        import keyboard
        import pickle

        keyboard.start_recording()
        keyboard.stop_recording()

        with open('keys.txt','rb') as f:
        keyboard.play(pickle.load(f))






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 10 at 16:16









        MartinqooNMartinqooN

        12




        12






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54029314%2fkeyboard-play-function-not-working-correctly%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas