Advertisement
Guest User

MuteOnKeypress revised

a guest
Mar 1st, 2014
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. ; MuteOnKeypress_v1.0.ahk
  2. ;
  3. ; AutoHotkey script to mute microphone once the keyboard is pressed
  4. ;
  5. ; @author Samuel Blomberg revised by Guillaume Fouet
  6. ; @date 3/1/2014
  7.  
  8. MuteKeysPressed := 0
  9. Muted := 0
  10. LastKey := 0
  11.  
  12. ; MuteUntil variable used to track the time from the last keypress
  13. MuteUntil := A_TickCount
  14. ; SetTimer creates a thread that executes MuteChecker every 250ms (0.25 seconds)
  15. SetTimer MuteChecker,250
  16.  
  17. ; All the main thread of this program will do is
  18. ; loop through this single set of commands. The
  19. ; Input, SingleKey, L1VI... line pauses the thread
  20. ; until a keyboard input is received. At that time
  21. ; the MuteUntil variable is changed to one second
  22. ; (1000ms) from the current time and the MuteMic()
  23. ; method is called
  24. Loop {
  25. Input, SingleKey, L1VI, {LControl}{RControl}{LAlt}{RAlt}{LShift}{RShift}{LWin}{RWin}{AppsKey}{F1}{F2}{F3}{F4}{F5}{F6}{F7}{F8}{F9}{F10}{F11}{F12}{Left}{Right}{Up}{Down}{Home}{End}{PgUp}{PgDn}{Del}{Ins}{BS}{Capslock}{Numlock}{PrintScreen}{Pause}
  26.  
  27. if (LastKey <> SingleKey) {
  28. MuteKeysPressed++
  29.  
  30. if ( MuteKeysPressed > 2 ) {
  31. MuteUntil := A_TickCount + 1000
  32. MuteKeysPressed := 3
  33. if (Muted = 0) {
  34. MuteMic()
  35. Muted = 1
  36. }
  37. }
  38. LastKey := SingleKey
  39. }
  40. }
  41.  
  42. ; This subroutine operates on a 250ms timer. Every
  43. ; time it is executed, it checks to see if the mic
  44. ; should be unmuted by comparing the MuteUntil variable
  45. ; with the current time
  46. MuteChecker:
  47. if ( MuteKeysPressed > 0 ) {
  48. MuteKeysPressed--
  49. }
  50.  
  51. If (MuteUntil < A_TickCount) {
  52. MuteKeysPressed := 0
  53. if (Muted = 1) {
  54. UnmuteMic()
  55. Muted = 0
  56. }
  57. }
  58. Return
  59.  
  60. ; Mutes system microphone
  61. MuteMic() {
  62. VA_SetMasterMute(true, "capture") ;<--Change what's between quotation marks with the system name of your microphone
  63. SoundBeep, 450, 30
  64. }
  65.  
  66. ; Unmutes system microphone
  67. UnmuteMic() {
  68. SoundBeep, 750, 30
  69. VA_SetMasterMute(false, "capture") ;<--Change what's between quotation marks with the system name of your microphone
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement