Arduino Keyboard library | Shortcuts

Поделиться
HTML-код
  • Опубликовано: 18 сен 2024
  • 🤩 FREE Arduino Crash Course 👇👇
    bit.ly/get_Ard...
    **Want to have some fun programming your own electronics?**
    bit.ly/3zSoke4
    **Get a great deal on a VPN with Private Internet Access - 82% OFF!**
    www.privateint...
    **Get the code, transcript, challenges, etc for this lesson on our website**
    bit.ly/3pawE3Z
    **We designed this circuit board for beginners!**
    Kit-On-A-Shield: amzn.to/3lfWClU
    FOLLOW US ELSEWHERE
    ---------------------------------------------------
    Facebook: / programmingelectronics...
    Twitter: / progelecacademy
    Website: www.programmin...
    ________________________________
    Are you using the Arduino keyboard library and you're trying to figure out how to do key combinations so you can do some type of keyboard shortcut? So basically you can have your Arduino board copy something, maybe like Command + Shift + C and then maybe paste it, Command + Shift + V, or whatever hot key combination you're trying to achieve with your Arduino board. You're trying to figure out how to do that. Well, in this lesson, we're gonna walk through a simple example of combining some key presses in order to do one of those hot key functions on a computer. Now, we also have another video about using the keyboard library. We'll make sure to link to that video in the description, but this video is gonna get specific on key press combinations. Now, the reason we're making this video is because one of our RUclips subscribers had a follow on question from that previous video, and I'm just trying to answer it as best as I can. All right. Let's get started. Well, before we dive in, I'd really appreciate if you could take a moment and click that subscribe button. It doesn't cost you but a click, but it really helps us grow our RUclips channel and bring you great content like this. All right, so here I am in a blank sketch. And what I wanna do is write some code that is gonna copy a line of text and then it's gonna paste that line of text directly after that line, all right? So basically let's say I've got a line of text here and I wanna write a program for my Arduino. And just so we're clear, we're talking about an Arduino that can simulate a USB device and that's not all Arduinos. Like an Arduino Uno can't do that but an Arduino Leonardo can, for example. So I wanna write a program where I can put my cursor somewhere and what this program will do is highlight all the text to the right of the cursor on a single line. It'll copy that line using Command + C or Control + C. It'll arrow down to the next line and then it will press Command or Control + V to paste that line. So, I want to write a program that's gonna do that, obviously, all hands off. The Arduino's gonna do it for me. So let's go ahead and do this. All right, so the first thing I want to do is include the keyboard library. So let me do that. All right, so the keyboard library is included and then I just threw the setup and the loop in here. If you don't have setup and loop, you can't compile the program. And just about after every line of code I write, I like to do a verify, you know? Compile the program just to make sure I haven't done any errors. So, go ahead and verify it now. All right, it's done compiling. So so far, I haven't screwed anything up. That's good. Now the next thing I'm gonna do and set up is a little precautionary thing. 'Cause what happens when you start telling your computer to emulate the keyboard and let's say you tell it to copy and paste stuff. Well, it does that really, really, really super fast. And if you're not careful, you can end up in a situation where anytime you plug in your Arduino board it starts copying, pasting code really quick. And it's hard to get a new sketch on there to stop that behavior. So I'm gonna do something that a viewer actually recommended, which was just put a delay in the setup that way anytime you plug in the board, power goes on to it, you're gonna have five seconds of nothing happening so you can upload a blank sketch or something like that. So here we go.
    CONTINUED...
    bit.ly/3pawE3Z
    **About Us:**
    This Arduino lesson was created by Programming Electronics Academy. We are an online education company who seeks to help people learn about electronics and programming through the ubiquitous Arduino development board.
    **We have no affiliation whatsoever with Arduino LLC, other than we think they are cool.**

Комментарии • 25

  • @jon_raymond
    @jon_raymond 2 года назад +1

    "I went to my favourite page on the the internet, the Arduino Reference page...." Had me chuckling. Thanks for the great tutorials!

  • @DerMarkus1982
    @DerMarkus1982 7 месяцев назад +1

    Shift+Ctrl+Right Arrow on Windows highlights one *word* to the right from the initial cursor position.
    Highlight the whole *line* of text to the right from the cursor position? Shift+End .
    Highlight the whole line of text start to end? Home; Shift+End . (You might know Home as Pos1, idk)

  • @danielvanmieghem1091
    @danielvanmieghem1091 Год назад

    Exactly what I was looking for . Thanks for this AWESOME tutorial. You just got an new subscriber.... Keep up the good work

  • @bits_volts
    @bits_volts 2 года назад

    Great tutorials, thanks!! What about the "fn" key from Mac's keyboard not available in the library?

  • @RezahVAL
    @RezahVAL 2 года назад +1

    so when I plug in my mouse to the host shield it charges my mouse .but I cannot move my mouse

  • @FaruQ_Q
    @FaruQ_Q Год назад +1

    error: 'Keyboard' was not declared in this scope
    Keyboard.press(KEY_LEFT_CTRL);

    • @s10jam
      @s10jam 5 месяцев назад

      He never declared it so I'm wondering how this code even runs correctly.

  • @SpiderDanification
    @SpiderDanification Год назад +1

    Wouldn’t it be good to add both key presses for Windows and Mac? The idea is to make it work on both systems. Or do the commands like copy and paste not work then?

    • @programmingelectronics
      @programmingelectronics  Год назад +1

      Great idea - i think you are correct, that would make it more generalizable. Though, and I could be wrong, I think you may need to change the code up, so board knows if it is attached to a mac or PC and adjust the keypresses accordingly.

  • @HKGoldenMrA
    @HKGoldenMrA 2 года назад +1

    6:00
    On Windows or Linux: Shift + End

  • @luca.ambroo3515
    @luca.ambroo3515 Год назад

    how can I make my arduino paste something that is stored in a string variable? is that possible?

  • @jackflight2756
    @jackflight2756 2 года назад

    Nice, but where can I find the RUclips movie where the flag portion is explained?

  • @phakalanep7241
    @phakalanep7241 2 года назад +2

    What code works with an uno?

  • @ItsKalle231
    @ItsKalle231 Год назад +1

    hello, its me again, it din't work, it says: exit status 1
    'keyboard' was not declared in this scope, and it says: Multiple libraries were found for "Keyboard.h"
    , so please help me

    • @programmingelectronics
      @programmingelectronics  Год назад +1

      In your sketch do you have Keyboard.h capitalized?
      Also, if you go to the libraries folder of your Arduino sketchbook location, which is usually under MyDocuments>Arduino>libraries
      Do you see more than one Keyboard library folder?

  • @rdvardi3296
    @rdvardi3296 11 месяцев назад

    Link install library kyboard please

  • @sajjadrahmanpour5758
    @sajjadrahmanpour5758 Год назад

    Why do I think that this code will copy and paste non-stop?!! Every time at the beginning of the loop, you set value of copiedflag to False. Then it should go into the if statement and execute the code. Am I wrong?!

    • @programmingelectronics
      @programmingelectronics  Год назад

      Great question Sajad!
      OK, the variable copiedFlag is declared as static.
      Variables declared as static will only be created and initialized the first time it is run in a function (in this case the loop).

  • @michaelcheich2481
    @michaelcheich2481 2 года назад

    Get a great deal on a VPN with Private Internet Access and support our channel -> 82% OFF
    www.privateinternetaccess.com/PEA