Is there any command statement to simulate pressing ctrl-c？

13299118606
Thu, 15 Jun 2023 12:08:44 +0000
General Usage

Is there any command statement to simulate pressing ctrl-c to abort the running program, I am designing a gui abort button, and I want it to press the button to stop the running program. Similar to the “interrupt()” function, note that this is not to exit julia, such as base.exit(0), because I can also click the run button to re-run the program.

If you use a third-party package to simulate the keyboard and press ctrl-c, it will abort the running program,you can introduce it

using GLMakie
fig = Figure()
btrun =Button(fig[1,1],label="run program",tellwidth=false)
on(btrun.clicks) do s;test();end
btexitprogram =Button(fig[1,2],label="exit program",tellwidth=false)
on(btexitprogram.clicks) do s;interrupt_callback();end
display(fig)

#function:

function interrupt_callback()
    throw(InterruptException())
end
function test()
    tstart=time()
    for i=1:100
        sleep(1)
        tend=time()-tstart
        println("time:$tend")
    end
end

4 posts - 2 participants