Created
September 18, 2020 12:54
-
-
Save AlexeyGy/68d3d63d14b3293035e09c0379a9a46a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"syscall" | |
"unsafe" | |
) | |
type keyboardInput struct { | |
wVk uint16 | |
wScan uint16 | |
dwFlags uint32 | |
time uint32 | |
dwExtraInfo uint64 | |
} | |
type input struct { | |
inputType uint32 | |
ki keyboardInput | |
padding uint64 | |
} | |
// PrintCharacters handles the output to the current window, | |
// CTRL and ALT are sent because they are pressed down when the user issues the shortcut | |
func PrintCharacters(sendInputProc *syscall.Proc, toPrint string) { | |
for i := 0; i < len(toPrint); i++ { | |
toPass := []input{} | |
// ALT key will be sent as a keyup | |
var altKeyUp input | |
altKeyUp.inputType = 1 | |
altKeyUp.ki.wVk = Keycodes["ALT"] // ALT | |
altKeyUp.ki.dwFlags = 0x0002 // the key is being released. | |
toPass = append(toPass, altKeyUp) | |
// CTRL key will be sent as a keyup | |
var ctrlKeyUp input | |
ctrlKeyUp.inputType = 1 | |
ctrlKeyUp.ki.wVk = Keycodes["CTRL"] // CTRL | |
ctrlKeyUp.ki.dwFlags = 0x0002 // the key is being released. | |
toPass = append(toPass, ctrlKeyUp) | |
// a key | |
var key input | |
key.inputType = 1 //INPUT_KEYBOARD | |
key.ki.wVk = Keycodes[string(toPrint[i])] | |
toPass = append(toPass, key) | |
ret, _, err := sendInputProc.Call( | |
uintptr(len(toPass)), | |
uintptr(unsafe.Pointer(&toPass[0])), | |
uintptr(unsafe.Sizeof(ctrlKeyUp)), | |
) | |
if err != nil { | |
log.Printf("ret: %v error: %v", ret, err) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment