Обновить autobudilnik.rb
This commit is contained in:
parent
b01d7edc86
commit
7e874f355d
260
autobudilnik.rb
260
autobudilnik.rb
@ -1,131 +1,131 @@
|
|||||||
# autobudilnik [-a <audiofilepath>] [-t <time>] [-c <configfilepath>]
|
# ruby autobudilnik.rb [-a <audiofilepath>] [-t <time>] [-c <configfilepath>]
|
||||||
#require 'io/console'
|
#require 'io/console'
|
||||||
require 'reline'
|
require 'reline'
|
||||||
|
|
||||||
za = [false,false,false]
|
za = [false,false,false]
|
||||||
nf = ''
|
nf = ''
|
||||||
da = ''
|
da = ''
|
||||||
audiofilepath = "audio.opus"
|
audiofilepath = "audio.opus"
|
||||||
waittime = 7200
|
waittime = 7200
|
||||||
configfilepath = "config.txt"
|
configfilepath = "config.txt"
|
||||||
i=0;while i<ARGV.size
|
i=0;while i<ARGV.size
|
||||||
if ARGV[i] == "-a"
|
if ARGV[i] == "-a"
|
||||||
if za[0] == false
|
if za[0] == false
|
||||||
i += 1
|
i += 1
|
||||||
za[0] = true
|
za[0] = true
|
||||||
audiofilepath = ARGV[i]
|
audiofilepath = ARGV[i]
|
||||||
else
|
else
|
||||||
#da.push ARGV[i] + (i += 1;" " + ARGV[i])
|
#da.push ARGV[i] + (i += 1;" " + ARGV[i])
|
||||||
da += " " + ARGV[i]
|
da += " " + ARGV[i]
|
||||||
#raise "duplicate arguments"
|
#raise "duplicate arguments"
|
||||||
end
|
end
|
||||||
elsif ARGV[i] == "-t"
|
elsif ARGV[i] == "-t"
|
||||||
if za[1] == false
|
if za[1] == false
|
||||||
i += 1
|
i += 1
|
||||||
za[1] = true
|
za[1] = true
|
||||||
waittime = ARGV[i].to_i
|
waittime = ARGV[i].to_i
|
||||||
else
|
else
|
||||||
#da.push ARGV[i] + (i += 1;" " + ARGV[i])
|
#da.push ARGV[i] + (i += 1;" " + ARGV[i])
|
||||||
da += " " + ARGV[i]
|
da += " " + ARGV[i]
|
||||||
#raise "duplicate arguments"
|
#raise "duplicate arguments"
|
||||||
end
|
end
|
||||||
elsif ARGV[i] == "-c"
|
elsif ARGV[i] == "-c"
|
||||||
if za[2] == false
|
if za[2] == false
|
||||||
i += 1
|
i += 1
|
||||||
za[2] = true
|
za[2] = true
|
||||||
configfilepath = ARGV[i]
|
configfilepath = ARGV[i]
|
||||||
else
|
else
|
||||||
#da.push ARGV[i] + (i += 1;" " + ARGV[i])
|
#da.push ARGV[i] + (i += 1;" " + ARGV[i])
|
||||||
da += " " + ARGV[i]
|
da += " " + ARGV[i]
|
||||||
#raise "duplicate arguments"
|
#raise "duplicate arguments"
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
#nf.push ARGV[i]
|
#nf.push ARGV[i]
|
||||||
nf += " " + ARGV[i]
|
nf += " " + ARGV[i]
|
||||||
#ARGV[i..ARGV.size].join(' ')
|
#ARGV[i..ARGV.size].join(' ')
|
||||||
end
|
end
|
||||||
i+=1
|
i+=1
|
||||||
end
|
end
|
||||||
|
|
||||||
puts "not found:" + nf if nf != ''
|
puts "not found:" + nf if nf != ''
|
||||||
if da.size != 0
|
if da.size != 0
|
||||||
raise 'duplicate arguments:' + da
|
raise 'duplicate arguments:' + da
|
||||||
end
|
end
|
||||||
|
|
||||||
if za[0] == false || za[1] == false
|
if za[0] == false || za[1] == false
|
||||||
configfilepath = File.absolute_path(configfilepath)
|
configfilepath = File.absolute_path(configfilepath)
|
||||||
if File.file? configfilepath
|
if File.file? configfilepath
|
||||||
puts 'reading config'
|
puts 'reading config'
|
||||||
File.readlines(configfilepath).each { |l|
|
File.readlines(configfilepath).each { |l|
|
||||||
lspl = l.split(' ')
|
lspl = l.split(' ')
|
||||||
if za[0] == false && ('audiofilepath'.start_with? lspl[0])
|
if za[0] == false && ('audiofilepath'.start_with? lspl[0])
|
||||||
audiofilepath = l.delete_prefix(lspl[0] + ' ').delete_prefix('"').delete_prefix("'").delete_suffix('"').delete_suffix("'")
|
audiofilepath = l.delete_prefix(lspl[0] + ' ').delete_prefix('"').delete_prefix("'").delete_suffix('"').delete_suffix("'")
|
||||||
#split('"')[0].split('"')[0]
|
#split('"')[0].split('"')[0]
|
||||||
elsif za[1] == false && ('waittime'.start_with? lspl[0])
|
elsif za[1] == false && ('waittime'.start_with? lspl[0])
|
||||||
waittime = lspl[1].to_i
|
waittime = lspl[1].to_i
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if za[2] == true
|
if za[2] == true
|
||||||
raise configfilepath + ' doesnt exist'
|
raise configfilepath + ' doesnt exist'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
puts 'waittime:' + waittime.to_s
|
puts 'waittime:' + waittime.to_s
|
||||||
audiofilepath = File.absolute_path(audiofilepath)
|
audiofilepath = File.absolute_path(audiofilepath)
|
||||||
puts 'audiofilepath:' + audiofilepath
|
puts 'audiofilepath:' + audiofilepath
|
||||||
raise audiofilepath + ' doesnt exist' unless File.file? audiofilepath
|
raise audiofilepath + ' doesnt exist' unless File.file? audiofilepath
|
||||||
nexttime = Time.new + waittime
|
nexttime = Time.new + waittime
|
||||||
waittime = waittime - 18 # 30 x 0.6 = 18
|
waittime = waittime - 18 # 30 x 0.6 = 18
|
||||||
=begin
|
=begin
|
||||||
STDIN.echo = false
|
STDIN.echo = false
|
||||||
STDIN.raw!
|
STDIN.raw!
|
||||||
|
|
||||||
getchr = false
|
getchr = false
|
||||||
Thread.new {while true do sleep(0.1);puts 't';STDIN.getbyte; getchr = true end}
|
Thread.new {while true do sleep(0.1);puts 't';STDIN.getbyte; getchr = true end}
|
||||||
puts "rtstrt"
|
puts "rtstrt"
|
||||||
while true
|
while true
|
||||||
sleep(1.4)
|
sleep(1.4)
|
||||||
if getchr == true
|
if getchr == true
|
||||||
nexttime = Time.new + waittime;puts nexttime
|
nexttime = Time.new + waittime;puts nexttime
|
||||||
getchr = false
|
getchr = false
|
||||||
end
|
end
|
||||||
if nexttime < Time.new
|
if nexttime < Time.new
|
||||||
puts "audioplay"
|
puts "audioplay"
|
||||||
system(audiofilepath)
|
system(audiofilepath)
|
||||||
end
|
end
|
||||||
#thr.run
|
#thr.run
|
||||||
end
|
end
|
||||||
=end
|
=end
|
||||||
|
|
||||||
puts 'autobudilnik running'
|
puts 'autobudilnik running'
|
||||||
a=Reline::Windows::Win32API.new('user32','GetAsyncKeyState','I','I')
|
a=Reline::Windows::Win32API.new('user32','GetAsyncKeyState','I','I')
|
||||||
a2=Reline::Windows::Win32API.new('user32','keybd_event','I','I')
|
a2=Reline::Windows::Win32API.new('user32','keybd_event','I','I')
|
||||||
|
|
||||||
b = []
|
b = []
|
||||||
c = []
|
c = []
|
||||||
while true
|
while true
|
||||||
255.times {|r|
|
255.times {|r|
|
||||||
b[r] = a.call(r)
|
b[r] = a.call(r)
|
||||||
}
|
}
|
||||||
if c != b
|
if c != b
|
||||||
nexttime = Time.now + waittime
|
nexttime = Time.now + waittime
|
||||||
end
|
end
|
||||||
sleep(3.4)
|
sleep(3.4)
|
||||||
255.times {|r|
|
255.times {|r|
|
||||||
c[r] = a.call(r)
|
c[r] = a.call(r)
|
||||||
}
|
}
|
||||||
if c != b
|
if c != b
|
||||||
nexttime = Time.now + waittime
|
nexttime = Time.now + waittime
|
||||||
end
|
end
|
||||||
if nexttime < Time.now
|
if nexttime < Time.now
|
||||||
30.times {
|
30.times {
|
||||||
sleep(0.6) #НУЖНО УБАВИТЬ С ВЭЙТТАЙМА
|
sleep(0.6) #НУЖНО УБАВИТЬ С ВЭЙТТАЙМА
|
||||||
a2.call(175)
|
a2.call(175)
|
||||||
}
|
}
|
||||||
puts "audioplay"
|
puts "audioplay"
|
||||||
system(audiofilepath)
|
system(audiofilepath)
|
||||||
end
|
end
|
||||||
sleep(3.4)
|
sleep(3.4)
|
||||||
end
|
end
|
Loading…
x
Reference in New Issue
Block a user