Hallo, I need to make in practice a application running in WIN7. This application must read continuously the sound(noise) received from the microphone and, if the level of the sound(noise) is higher that a adjustable value, to activate to display some random files (messages) on the screen and at the same time to deactivate the mouse and the keyboard. To have a adjusted delay and after the delay time to reactivate the mouse and the keyboard.
I succed this but I have a problem: With the command BlockInputBlockInput True all the keys in keyboard are disabled, but if I press AltCtrlDel the BlockInput turn to False (pressing AlyCtrlDel, mouse and keyboard are activated).
What I need to succed is that the user to not be able to interupt the message to all his display.

Recommended Answers

All 2 Replies

This is the programm:

Option Explicit

Dim DevHandle As Long
Dim InData(0 To 511) As Byte
Dim Inited As Boolean
Dim MinHeight As Long, MinWidth As Long
Dim lngTempTime
Dim Res
Public data As String
Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
Private Declare Function BlockInput Lib "user32" (ByVal fBlock As Long) As Long
Public Declare Function timeGetTime Lib "winmm.dll" () As Long

Private Declare Sub keybd_event Lib "user32" (  ByVal bVk As Byte, ByVal bScan As Byte,     ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

        Const KEYEVENTF_KEYUP = &H2
        Const VK_LWIN = &H5B
        Const VK_LALT = &HA4
        Const VK_F4 = &H73

Public Declare Function Beep Lib "kernel32"   (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long

'********** API for Wave Audio ************

Public Type WaveFormatEx

    Channels As Integer
    SamplesPerSec As Long
    AvgBytesPerSec As Long
    BlockAlign As Integer
    BitsPerSample As Integer
    ExtraDataSize As Integer
End Type

Public Type WaveHdr
    lpData As Long
    dwBufferLength As Long
    dwBytesRecorded As Long
    dwUser As Long
    dwFlags As Long
    dwLoops As Long
    lpNext As Long
    Reserved As Long
End Type

Public Type WaveInCaps
    ManufacturerID As Integer
    ProductID As Integer
    DriverVersion As Long
    ProductName(1 To 32) As Byte
    Formats As Long
    Channels As Integer
    Reserved As Integer
End Type

Public Const WAVE_INVALIDFORMAT = &H0&                 'invalid format
Public Const WAVE_FORMAT_1M08 = &H1&                   '11.025 kHz, Mono,   8-bit
Public Const WAVE_FORMAT_1S08 = &H2&                   '11.025 kHz, Stereo, 8-bit
Public Const WAVE_FORMAT_1M16 = &H4&                   '11.025 kHz, Mono,   16-bit
Public Const WAVE_FORMAT_1S16 = &H8&                   '11.025 kHz, Stereo, 16-bit
Public Const WAVE_FORMAT_2M08 = &H10&                  '22.05  kHz, Mono,   8-bit
Public Const WAVE_FORMAT_2S08 = &H20&                  '22.05  kHz, Stereo, 8-bit
Public Const WAVE_FORMAT_2M16 = &H40&                  '22.05  kHz, Mono,   16-bit
Public Const WAVE_FORMAT_2S16 = &H80&                  '22.05  kHz, Stereo, 16-bit
Public Const WAVE_FORMAT_4M08 = &H100&                 '44.1   kHz, Mono,   8-bit
Public Const WAVE_FORMAT_4S08 = &H200&                 '44.1   kHz, Stereo, 8-bit
Public Const WAVE_FORMAT_4M16 = &H400&                 '44.1   kHz, Mono,   16-bit
Public Const WAVE_FORMAT_4S16 = &H800&                 '44.1   kHz, Stereo, 16-bit

Public Const WAVE_FORMAT_PCM = 1

Public Const WHDR_DONE = &H1&
Public Const WHDR_PREPARED = &H2&
Public Const WHDR_BEGINLOOP = &H4&
Public Const WHDR_ENDLOOP = &H8&
Public Const WHDR_INQUEUE = &H10&

Public Const WIM_OPEN = &H3BE
Public Const WIM_CLOSE = &H3BF
Public Const WIM_DATA = &H3C0

Public Declare Function waveInAddBuffer Lib "winmm" (ByVal InputDeviceHandle As Long, ByVal WaveHdrPointer As Long, ByVal WaveHdrStructSize As Long) As Long
Public Declare Function waveInPrepareHeader Lib "winmm" (ByVal InputDeviceHandle As Long, ByVal WaveHdrPointer As Long, ByVal WaveHdrStructSize As Long) As Long
Public Declare Function waveInUnprepareHeader Lib "winmm" (ByVal InputDeviceHandle As Long, ByVal WaveHdrPointer As Long, ByVal WaveHdrStructSize As Long) As Long

Public Declare Function waveInGetNumDevs Lib "winmm" () As Long
Public Declare Function waveInGetDevCaps Lib "winmm" Alias "waveInGetDevCapsA" (ByVal uDeviceID As Long, ByVal WaveInCapsPointer As Long, ByVal WaveInCapsStructSize As Long) As Long

Public Declare Function waveInOpen Lib "winmm" (WaveDeviceInputHandle As Long, ByVal WhichDevice As Long, ByVal WaveFormatExPointer As Long, ByVal CallBack As Long, ByVal CallBackInstance As Long, ByVal Flags As Long) As Long
Public Declare Function waveInClose Lib "winmm" (ByVal WaveDeviceInputHandle As Long) As Long

Public Declare Function waveInStart Lib "winmm" (ByVal WaveDeviceInputHandle As Long) As Long
Public Declare Function waveInReset Lib "winmm" (ByVal WaveDeviceInputHandle As Long) As Long
Public Declare Function waveInStop Lib "winmm" (ByVal WaveDeviceInputHandle As Long) As Long

Public Sub Main()
    Dim ret As Long
    Dim Wave As WaveHdr
    Dim i As Long
    Dim WaveFormat As WaveFormatEx

   With WaveFormat
      .FormatTag = WAVE_FORMAT_PCM
      .Channels = 2
      .SamplesPerSec = 11025 '11khz
      .BitsPerSample = 8
      .BlockAlign = (.Channels * .BitsPerSample) \ 8
      .AvgBytesPerSec = .BlockAlign * .SamplesPerSec
      .ExtraDataSize = 0
   End With

   ret = waveInOpen(DevHandle, 0, VarPtr(WaveFormat), 0, 0, 0)
   ret = waveInStart(DevHandle)

    Wave.lpData = VarPtr(InData(0))
    Wave.dwBufferLength = 512

   Do
     ret = waveInPrepareHeader(DevHandle, VarPtr(Wave), Len(Wave))
     ret = waveInAddBuffer(DevHandle, VarPtr(Wave), Len(Wave))
     Do
        lngTempTime = timeGetTime
        Do Until timeGetTime > lngTempTime + 100   'loop until 100mS has elapsed
        Loop
     Loop Until ((Wave.dwFlags And WHDR_DONE) = WHDR_DONE) Or DevHandle = 0
     ret = waveInUnprepareHeader(DevHandle, VarPtr(Wave), Len(Wave))

** 'Start program message
If InData(0) > 130 Then
BlockInput True 'block the mouse and keyboard input
Call MinimizeWindows
Sleep 1000 ' wait for 1 seconds
Beep 880, 2000
Res = Shell("Explorer.exe " & "C:\Silence" & RandomInteger(1, 3) & ".ppsx", vbHide)
Sleep 66000 ' wait for 66 seconds
Call CloseWindow
BlockInput False 'unblock the mouse and keyboard input
End If**
DoEvents 'allow windows to update the gui.
Loop While DevHandle <> 0 'While the audio device is open
End Sub

Private Sub MinimizeWindows()
         Call keybd_event(VK_LWIN, 0, 0, 0)
         Call keybd_event(77, 0, 0, 0)    ' 77 is code for the letter 'M'
         Call keybd_event(77, 0, KEYEVENTF_KEYUP, 0)
         Call keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0)
      End Sub

Private Sub CloseWindow()
         Call keybd_event(VK_LALT, 0, 0, 0)
         Call keybd_event(VK_F4, 0, 0, 0)
         Call keybd_event(VK_F4, 0, KEYEVENTF_KEYUP, 0)
         Call keybd_event(VK_LALT, 0, KEYEVENTF_KEYUP, 0)
      End Sub

Private Function RandomInteger(Lowerbound As Integer, Upperbound As Integer) As Integer
    RandomInteger = Int((Upperbound - Lowerbound + 1) * Rnd + Lowerbound)
End Function

Ctrl+Alt+Del is a system event and cannot be blocked (though it could be blocked in Vista by modifying the registry). This event is handled in msgina.dll. To disable Ctrl-Alt-Del, you need to write your own msgina.dll. The idea is to pass everything through to msgina.dll except for when Ctrl-Alt-Del is handled.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.