Jump to content

Key hit and Speech


DaLiMan
 Share

Recommended Posts

Hi there,

After testing it here on my work with a collegea I thought it might be usefull for other people to. :(

Please use it how you like and let me now what you think.

NOTE:

Use Windows key + F2 to select speech YES or NO

Use Windows key + F12 to open the options dialog.

Use Windows key + ESC to Exit the program

Here's the code:

#include <GUIConstants.au3>
; Credits go to:
; KeyLog Code originally created by : jazo10.
; Text Speech code originally created by : MHz.
; gafrost and Wb-FreeKill for helping me with _WaveVolGet()
;
;=================================================Compiler opties==========================================================
#Region Compiler directives section
#Compiler_Prompt = n
#Compiler_Compression = 2
#Compiler_Allow_Decompile = y
#Compiler_Res_Comment = Speeks the typed text back to you.
#Compiler_Res_Description = KeySpeech ©
#Compiler_Res_Field1Name = Auteur
#Compiler_Res_Field1Value = Daniel Lith
#Compiler_Run_AU3Check = y
#Compiler_Res_Fileversion = 1.0.5.2
#EndRegion
;===============================================Current Version========================================================
Global $Versie = FileGetVersion(@ScriptFullPath)
Global $Name = "KeySpeech ©"

Global $Speech = 1
Global $user32
Global $Log
Global $date
Global $window2
Global $WaveSet
Global $WaveVol
Global $HotKeyCount = 0
Global $DoOnce = 0

Global $user32 = DllOpen("user32")

HotKeySet("#{F2}", "_SpeechYesNo"); Use Windows key + F2 to select speech YES or NO
HotKeySet("#{F12}", "_SetVolumeGUI"); Use Windows key + F12 to open the options dialog.
HotKeySet("#{ESC}", "Terminate"); Use Windows key + ESC to Exit the program
Break(1);allow close from the tasktray
opt("OnExitFunc", "Terminate")

;===================================end program header, begin program=====================================

While 1
; ============================ A - Z / 0 - 9 ===================================
    For $n = 30 To 39; 1 TM 9
        If _IsPressed($n) Then
            _KeySpeech(Chr($n + 18))
        EndIf
    Next
    
    For $n = 60 To 69; 1 TM 9 NUMPAD
        If _IsPressed($n) Then
            _KeySpeech(Chr($n - 12))
        EndIf
    Next
    
    For $n = 41 To 49; A TM I
        If _IsPressed($n) Then
            _KeySpeech(Chr($n + 56))
        EndIf
    Next
    
    If _IsPressed('4a') Then
        _KeySpeech("j")
    EndIf
    
    
    If _IsPressed('4b') Then
        _KeySpeech("k")
    EndIf
    
    
    If _IsPressed('4c') Then
        _KeySpeech("l")
    EndIf
    
    
    If _IsPressed('4d') Then
        _KeySpeech("m")
    EndIf
    
    
    If _IsPressed('4e') = 1 Then
        _KeySpeech("n")
    EndIf
    
    
    If _IsPressed('4f') Then
        _KeySpeech("o")
    EndIf
    
    For $n = 50 To 59; P TM Y
        If _IsPressed($n) Then
            _KeySpeech(Chr($n + 62))
        EndIf
    Next
    
    If _IsPressed('5a') Then
        _KeySpeech("z")
    EndIf
; ============================ SPECIAL KEY / CHAR. ===================================
    
    If _IsPressed('01') Then
        _KeySpeech("<font color=#008000 style=font-size:9px><i>LEFT MOUSE</i></font>")
    EndIf
    
    If _IsPressed('02') Then
        _KeySpeech("<font color=#008000 style=font-size:9px><i>RIGHT MOUSE</i></font>")
    EndIf
    
    
    If _IsPressed('08') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>BACKSPACE</i></font>")
    EndIf
    
    
    If _IsPressed('09') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>TAB</i></font>")
    EndIf
    
    
    If _IsPressed('0d') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>ENTER</i></font>")
    EndIf
    
    
    If _IsPressed('10') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>SHIFT</i></font>")
    EndIf
    
    
    If _IsPressed('11') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>CONTROL</i></font>")
    EndIf
    
    
    If _IsPressed('12') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>ALT</i></font>")
    EndIf
    
    
    If _IsPressed('13') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>PAUSE</i></font>")
    EndIf
    
    
    If _IsPressed('14') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>CAPSLOCK</i></font>")
    EndIf
    
    
    If _IsPressed('1b') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>ESCAPE</i></font>")
    EndIf
    
    
    If _IsPressed('20') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>SPACE</i></font>")
    EndIf
    
    
    If _IsPressed('21') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>PAGE UP</i></font>")
    EndIf
    
    
    If _IsPressed('22') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>PAGE DOWN</i></font>")
    EndIf
    
    
    If _IsPressed('23') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>END</i></font>")
    EndIf
    
    
    If _IsPressed('24') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>HOME</i></font>")
    EndIf
    
    
    If _IsPressed('25') Then
        _KeySpeech("<font color=#008000 style=font-size:9px><i>LEFT ARROW</i></font>")
    EndIf
    
    
    If _IsPressed('26') Then
        _KeySpeech("<font color=#008000 style=font-size:9px><i>UP ARROW</i></font>")
    EndIf
    
    
    If _IsPressed('27') Then
        _KeySpeech("<font color=#008000 style=font-size:9px><i>RIGHT ARROW</i></font>")
    EndIf
    
    
    If _IsPressed('28') Then
        _KeySpeech("<font color=#008000 style=font-size:9px><i>DOWN ARROW</i></font>")
    EndIf
    
    
    If _IsPressed('2c') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>PRINT SCREEN</i></font>")
    EndIf
    
    
    If _IsPressed('2d') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>INSERT</i></font>")
    EndIf
    
    
    If _IsPressed('2e') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>DELETE</i></font>")
    EndIf
    
    If _IsPressed('5b') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>LEFT WINDOW KEY</i></font>")
    EndIf
    
    If _IsPressed('5c') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>RIGHT WINDOW KEY</i></font>")
    EndIf
    
    If _IsPressed('5d') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>APPLICATION KEY</i></font>")
    EndIf
    
    If _IsPressed('6a') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>ADD KEY</i></font>")
    EndIf
    
    If _IsPressed('6b') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>FIELD PLUS</i></font>")
    EndIf
    
    If _IsPressed('6c') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>SEPERATOR KEY</i></font>")
    EndIf
    
    If _IsPressed('6d') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>SUBSTRACT KEY</i></font>")
    EndIf
    
    If _IsPressed('6e') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>DECIMAL KEY</i></font>")
    EndIf
    
    If _IsPressed('6f') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>DIVIDE KEY</i></font>")
    EndIf
    
    If _IsPressed('70') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>F1</i></font>")
    EndIf
    
    If _IsPressed('90') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>NUM LOCK</i></font>")
    EndIf
    
    If _IsPressed('91') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>SCROLL LOCK</i></font>")
    EndIf
    
    If _IsPressed('BA') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>;</i></font>")
    EndIf
    
    If _IsPressed('BB') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>=</i></font>")
    EndIf
    
    If _IsPressed('BC') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>,</i></font>")
    EndIf
    
    If _IsPressed('BD') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>-</i></font>")
    EndIf
    
    If _IsPressed('BE') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>.</i></font>")
    EndIf
    
    If _IsPressed('BF') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>/</i></font>")
    EndIf
    
    If _IsPressed('C0') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>BACK QUOTE</i></font>")
    EndIf
    
    If _IsPressed('DB') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>[</i></font>")
    EndIf
    
    If _IsPressed('DC') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>\</i></font>")
    EndIf
    
    If _IsPressed('DD') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>]</i></font>")
    EndIf
    
    If _IsPressed('DE') Then
        _KeySpeech("<font color=#FF8000 style=font-size:9px><i>'</i></font>")
    EndIf
; ============================ F1 TM F12 ===================================
    
    For $n = 70 To 79; F1 TM F10
        If _IsPressed($n) Then
            Global $Fkey = "F" & $n - 69
            _KeySpeech("<font color=#FF8000 style=font-size:9px><i>" & $Fkey & "</i></font>")
        EndIf
    Next
    
    If _IsPressed('7a') Then
        _KeySpeech("F11")
    EndIf
    
    If _IsPressed('7b') Then
        _KeySpeech("F12")
    EndIf
    
    If _IsPressed('7b') Then
        _KeySpeech("F12")
    EndIf
    
WEnd

;=================================================All Functions=================================================
Func _IsPressed($hexKey)
    Local $aR, $bRv
    $hexKey = '0x' & $hexKey
    $aR = DllCall($user32, "int", "GetAsyncKeyState", "int", $hexKey)
    If $aR[0] <> 0 Then
        $bRv = 1
    Else
        $bRv = 0
    EndIf
    Return $bRv
EndFunc  ;==>_IsPressed
;-----------------------------------------------------------------------------------------------------
Func _KeySpeech($what2log)
; Only Talk when wanted to.
    If $Speech = 1 Then
        _Say($what2log)
    EndIf
EndFunc  ;==>_KeySpeech
;-----------------------------------------------------------------------------------------------------
Func _SpeechYesNo()
    If $Speech = 0 Then
        $Speech = 1
    Else
        $Speech = 0
    EndIf
    Return
EndFunc  ;==>_SpeechYesNo
;-----------------------------------------------------------------------------------------------------
Func _Say($text)
    $talk = ObjCreate ('SAPI.SpVoice')
    If Not @error Then $talk.Speak ($text)
    Return
EndFunc  ;==>_Say
;-----------------------------------------------------------------------------------------------------
Func _WaveVolGet()
;
; Thanks to gafrost and Wb-FreeKill
;
    Const $MMSYSERR_NOERROR = 0
    $p = DllStructCreate ("dword")
    If @error Then
        MsgBox(0, "", "Error in DllStructCreate " & @error);
        Exit
    EndIf
    Dim $v
    $ret = DllCall("winmm.dll", "long", "waveOutGetVolume", "long", -1, "long", DllStructGetPtr ($p))
    If ($ret[0] == $MMSYSERR_NOERROR) Then
        Global $WaveVol = Round(Dec(StringRight(Hex(DllStructGetData ($p, 1), 8), 4)) / 0xFFFF * 100)
    EndIf
    DllStructDelete ($p)
    
EndFunc  ;==>_WaveVolGet
;-----------------------------------------------------------------------------------------------------
Func _SetVolumeGUI()
    
    GUICreate($Name & " - v." & $Versie, 220, 295, 100, 50, $WS_DLGFRAME)
    GUISetBkColor(0xFFFFFF) ; will change background color
    
    
    $slider1 = GUICtrlCreateSlider(10, 10, 200, 30)
    GUICtrlSetColor(-1, 0xff0000)
    
    $SetVolume = GUICtrlCreateButton("Set Volume", 10, 50, 200, 40)
    GUICtrlSetFont(-1, 21, 800)
    
    $MinVol = GUICtrlCreateButton("-", 10, 90, 100, 40)
    GUICtrlSetFont(-1, 21, 800)
    
    $PlusVol = GUICtrlCreateButton("+", 110, 90, 100, 40)
    GUICtrlSetFont(-1, 21, 800)
    
    $SpeechYesNo = GUICtrlCreateButton("Speech", 10, 150, 200, 40)
    GUICtrlSetFont(-1, 21, 800)
    If $Speech = 1 Then
        GUICtrlSetData($SpeechYesNo, "Speech ON")
    ElseIf $Speech = 0 Then
        GUICtrlSetData($SpeechYesNo, "Speech OFF")
    EndIf
    
    $Cancel = GUICtrlCreateButton("Cancel", 10, 210, 100, 40)
    GUICtrlSetFont(-1, 21, 800)
    
    $ShutDown = GUICtrlCreateButton("STOP", 110, 210, 100, 40)
    GUICtrlSetFont(-1, 21, 800)
    
    $Daniel = GUICtrlCreateLabel("Daniel Lith - 2005 ©", 10, 255, 200, 12, $SS_CENTER)
    
    _WaveVolGet()
    GUISetState()
    GUICtrlSetData($slider1, $WaveVol); set current volume
    
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $SetVolume
                $WaveSet = GUICtrlRead($slider1)
                SoundSetWaveVolume($WaveSet)
                _Say("SET VOLUME")
                _WaveVolGet()
                GUICtrlSetData($slider1, $WaveVol); set current volume
                
            Case $msg = $PlusVol
                $WaveSet = $WaveVol + 10
                If $WaveSet > 100 Then $WaveSet = 100
                SoundSetWaveVolume($WaveSet)
                _Say("SET VOLUME")
                _WaveVolGet()
                GUICtrlSetData($slider1, $WaveVol); set current volume
                
            Case $msg = $MinVol
                $WaveSet = $WaveVol - 10
                If $WaveSet < 0 Then $WaveSet = 0
                SoundSetWaveVolume($WaveSet)
                _Say("SET VOLUME")
                _WaveVolGet()
                GUICtrlSetData($slider1, $WaveVol); set current volume
                
            Case $msg = $SpeechYesNo
                _SpeechYesNo()
                If $Speech = 1 Then
                    GUICtrlSetData($SpeechYesNo, "Speech ON")
                ElseIf $Speech = 0 Then
                    GUICtrlSetData($SpeechYesNo, "Speech OFF")
                EndIf
                
            Case $msg = $ShutDown
                $ShutDownMsg = MsgBox(4, $Name & " - v." & $Versie, "Weet u zeker dat u het programma wilt stoppen?", 5)
                If $ShutDownMsg = 6 Then Terminate()
                ExitLoop
                
            Case $msg = $Cancel
                ExitLoop
                
        EndSelect
    WEnd
    GUIDelete()
EndFunc  ;==>_SetVolumeGUI
;-----------------------------------------------------------------------------------------------------
Func Terminate()
    DllClose($user32)
    Sleep(1000)
    Exit
EndFunc  ;==>Terminate
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...