PDA

View Full Version : Not exactly a productivity tool, but...



Petr Schreiber
17-10-2014, 20:44
... did you ever wondered, how productive you would be in writing anything, if every touch to the keyboard would cause different sound?

No?

Well, that indicates you are... sane :) But just in case, try this script:


Uses "WinMM", "UI"

Begin Const
%MIDI_ChangeInstrument = 192
%MIDI_NoteOn = 144
%MIDI_NoteOff = 128
End Const

Function TBMain()

Long hmidiOut
Long instrument, duration, note, i
Single velocity

velocity = 50
note = 50
duration = 4

Long Device = 0
Long tNow, tLast

MidiOut_Close hmidiOut
If MidiOut_Open hmidiOut, 0, Device, 0, 0 <> 0 Then
MsgBox 0, "Unable to open MidiOut port!"
Exit Function
End If

tLast = GetTickCount
Do
tNow = GetTickCount

For i = 1 To 255
If GetAsyncKeyState(i) Then
velocity = Rnd(0,127)
note = Rnd(0,127)
instrument = Rnd(0,127)
MidiOut_ShortMsg hmidiOut, Rgb(%MIDI_ChangeInstrument, instrument, 127)
MidiOut_ShortMsg hmidiOut, Rgb(%MIDI_NoteOn, 12 + note, velocity)

Sleep duration

MidiOut_ShortMsg hmidiOut, Rgb(%MIDI_NoteOff, 12 + note, 127)

tLast = GetTickCount
End If
Next

If GetAsyncKeyState(%VK_ESCAPE) Then
Exit Do
End If

Loop
MidiOut_Close hmidiout

End Function


Once the headache comes, simply press ESC anytime, and the keyboard will stop doing those... noises.


Have a nice weekend!,
Petr

P.S. Tip: Do not run this script from thinAir, but launch it by clicking. This will allow smooth thinAir "experience"

Billbo
18-10-2014, 02:26
Petr,

It sure is a neat program. Plus, what I've noticed
that's different from others that even come close is
that the sound is different each time you press the
same key.

Great little program.

Bill