save
This commit is contained in:
parent
93f402b012
commit
7b35ea96bb
2 changed files with 116 additions and 0 deletions
100
bin/sq
Executable file
100
bin/sq
Executable file
|
|
@ -0,0 +1,100 @@
|
|||
#!/usr/bin/env ruby
|
||||
require 'socket'
|
||||
|
||||
# Path to QEMU monitor socket
|
||||
sock_path = "/tmp/qemu-monitor.sock"
|
||||
|
||||
# Connect to UNIX socket
|
||||
sock = UNIXSocket.new(sock_path)
|
||||
|
||||
# Read greeting from QEMU (optional)
|
||||
puts sock.readline rescue nil
|
||||
|
||||
# Function to send a single keystroke
|
||||
def send_key(sock, key)
|
||||
cmd = "sendkey #{key}\n"
|
||||
puts ">>> #{cmd.strip}"
|
||||
sock.write(cmd)
|
||||
end
|
||||
|
||||
def char_to_key(ch)
|
||||
case ch
|
||||
# Control characters
|
||||
when "\n" then "ret"
|
||||
when "\t" then "tab"
|
||||
when " " then "spc"
|
||||
when "\e" then "esc"
|
||||
when "\b" then "backspace"
|
||||
|
||||
# Lowercase letters
|
||||
when "a".."z" then ch
|
||||
|
||||
# Uppercase letters (shift + letter)
|
||||
when "A".."Z" then "shift-#{ch.downcase}"
|
||||
|
||||
# Digits
|
||||
when "0".."9" then ch
|
||||
|
||||
# Shifted number row
|
||||
when "!" then "shift-1"
|
||||
when "@" then "shift-2"
|
||||
when "#" then "shift-3"
|
||||
when "$" then "shift-4"
|
||||
when "%" then "shift-5"
|
||||
when "^" then "shift-6"
|
||||
when "&" then "shift-7"
|
||||
when "*" then "shift-8"
|
||||
when "(" then "shift-9"
|
||||
when ")" then "shift-0"
|
||||
|
||||
when "-" then "minus"
|
||||
when "_" then "shift-minus"
|
||||
when "=" then "equal"
|
||||
when "+" then "shift-equal"
|
||||
when "[" then "bracket_left"
|
||||
when "{" then "shift-bracket_left"
|
||||
when "]" then "bracket_right"
|
||||
when "}" then "shift-bracket_right"
|
||||
when "\\" then "backslash"
|
||||
when "|" then "shift-backslash"
|
||||
when ";" then "semicolon"
|
||||
when ":" then "shift-semicolon"
|
||||
when "'" then "apostrophe"
|
||||
when "\"" then "shift-apostrophe"
|
||||
when "," then "comma"
|
||||
when "<" then "shift-comma"
|
||||
when "." then "dot"
|
||||
when ">" then "shift-dot"
|
||||
when "/" then "slash"
|
||||
when "?" then "shift-slash"
|
||||
when "`" then "grave_accent"
|
||||
when "~" then "shift-grave_accent"
|
||||
|
||||
else
|
||||
raise "Unsupported character: #{ch.inspect}"
|
||||
end
|
||||
end
|
||||
|
||||
if ARGV[0]
|
||||
puts ARGV[0]
|
||||
input = ARGV[0]
|
||||
puts "Typing: #{input.inspect}"
|
||||
|
||||
input.chars.each do |ch|
|
||||
send_key(sock, char_to_key(ch))
|
||||
sleep 0.1
|
||||
end
|
||||
|
||||
else
|
||||
# Example: type "hello<Enter>"
|
||||
%w[p a s s ret].each do |k|
|
||||
send_key(sock, k)
|
||||
sleep 0.1
|
||||
end
|
||||
end
|
||||
|
||||
sock.close
|
||||
|
||||
|
||||
# (qemu) screendump /Volumes/Cache/homes/debian/guaset.ppm
|
||||
# ffmpeg -y -i guaset.ppm guest.png
|
||||
|
|
@ -152,6 +152,7 @@ module Qemu
|
|||
|
||||
# -virtfs local,path=.,mount_tag=hostfs,security_model=passthrough,id=hostfs
|
||||
# mount -t 9p -o trans=virtio,version=9p2000.L hostfs /mnt
|
||||
# sudo mount -t 9p hostfs /home/user/Share -o trans=virtio,version=9p2000.L,uid=1000,gid=1000,msize=262144,cache=mmap
|
||||
|
||||
# hostfs /home 9p trans=virtio,version=9p2000.L,uid=1000,gid=1000,msize=262144,cache=mmap,nofail 0 0
|
||||
# hostfs /share 9p trans=virtio,version=9p2000.L,uid=1000,gid=1000,msize=262144,cache=mmap,nofail 0 0
|
||||
|
|
@ -237,6 +238,7 @@ module Qemu
|
|||
|
||||
### TODO: remove
|
||||
port = 2222
|
||||
args += ['-device', 'virtio-net-pci,netdev=net0']
|
||||
args += ['-netdev', "user,id=net0,hostfwd=tcp:127.0.0.1:#{port}-:22,hostfwd=udp:127.0.0.1:6544-:6544"]
|
||||
args += ['-virtfs', 'local,path=.,mount_tag=hostfs,security_model=passthrough,id=hostfs']
|
||||
### TODO END
|
||||
|
|
@ -326,3 +328,17 @@ module Qemu
|
|||
end
|
||||
|
||||
|
||||
|
||||
|
||||
## Works on MacOS=
|
||||
# -monitor unix:/tmp/qemu-monitor.sock,server,nowait
|
||||
# nc -U /tmp/qemu-monitor.sock
|
||||
# instead of args += ['-monitor', 'stdio']
|
||||
|
||||
|
||||
|
||||
|
||||
# 9P
|
||||
# sudo mount -t 9p hostfs /home/user/Share \
|
||||
# -o trans=virtio,version=9p2000.L,msize=262144,cache=mmap,access=any,dfltuid=1000,dfltgid=1000
|
||||
# sudo chown -hR 1000:1000 /home/user/Share
|
||||
Loading…
Add table
Add a link
Reference in a new issue