Posted by: Paul Lefebvre
by Erick Tejkowski
Should you accidentally enter the wrong password while logging onto an OS X machine, you’ll notice that the login window wiggles back and forth a few times. In fact, it looks like the login window is shaking its head “NO!” at you. This week we’ll look at how to implement this functionality with REALbasic. It turns out that it’s very simple to accomplish, so let’s get started.
Build the Interface
Launch REALbasic and open the default Window1. To this window, add a PushButton and a Timer. Set the Mode property of the Timer to 0 (zero). You can arrange the window however you wish.
Add the Code
Open the Code Editor for Window1 and add two properties to the window:
- OrigX As Integer
- Wiggle As Integer
Next, enter this code in the Action event of PushButton1:
Wiggle = 0 OrigX = Self.Left Timer1.Period = 30 Timer1.Mode = 2
Finally, add this code to the Action event of Timer1:
If Wiggle > 5 Then Me.Mode = 0 Self.Left = OrigX Else If (Wiggle Mod 2) = 0 Then Self.Left = OrigX - 20 Else Self.Left = OrigX + 20 End If Wiggle = Wiggle + 1 End If
By clicking the PushButton, you reset some variables that keep track of the position of the window as well as the number of wiggles. Then, the timer starts firing. As the timer fires, it increases the wiggle counter and alternates the position of the window between its two positions. Once the counter exceeds 5, the timer stops. Simple, eh?
Conclusion
That’s all there is to it.
Download Wiggle Window REALbasic project
Originally published by ResExcellence
Reprinted with permission

