64
zshh
7y

My first experience with Swift ended in me infecting myself with a virus (kinda). I wanted to create a macOS app that would listen for a global key event, catch it and then type a word.

During development I set it up to listen for ANY key event and to type "BALLS". So what happened? I compiled the code, everything looked good, I started the app and pressed a key which emitted a key event. The event was caught by my app and it typed "BALLS", just as expected. However, the typing of the word caused a NEW key event to be emitted, which the app also caught. The infinite loop was a fact. FUCK!

I tried closing down XCode but all I could see was "BALLS BALLS BALLS" everywhere. I tried everything I knew but it just kept typing "BALLS". I had to hold down my power button to make it stop.

I finally finished the app (which I named "The Balls App", I kept the word "BALLS"). I solved this issue by only listening for KeyUp and when emitting the "BALLS" word I just used KeyDown.

Comments
  • 10
    Nice. welcone to event programing!
    always make sure your event handler does not trigger the event you are listening to.
    seems trivial, but not as much as you thing it is.
  • 2
    What a problem xD.
  • 2
  • 9
    BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS BALLS βšΎπŸŽ±πŸŽ³πŸŽΎπŸ“πŸ€πŸπŸπŸ€πŸπŸ‘πŸ“πŸŽΎβšΎπŸŽ³πŸŽ±πŸˆπŸ‰βš½βš½πŸ₯…β­•β­•πŸ”΄πŸ”΄πŸ”΄πŸ”΄βšͺ⚫βšͺ
  • 3
    Balls hell
  • 2
    Takes balls to make that app
  • 0
    Yeah, about 15 years ago there not so many antiviruses, I remember only 3: avast, MacAfee, and Kaspersky. All of these are awesome in their specific fields, I mean each has its pros and cons. When it comes to Mac, somebody keeps saying "there are no viruses on Mac!". But I am answering: "Well, let's bet on 100$ - if https://macsecurity.net/view/... won't find anything, 100$ comes to me. In another scenario - comes to you". I have already gained 500$:)
Add Comment