Restricting mouse and keyboard in autoit? - keyboard

I'm trying to create a script so that during a task my keyboard/mouse is restricted from use aswell as whilst waiting for something what doesn't have a trigger/way of detecting if it's done I need it to stop me or anyone from moving the mouse/typing for at least 40 seconds.
Would this be possible to do in autoit and if so does anyone know how I can acheive this?
thanks GTPE

You're looking for BlockInput() which allows you to block keyboard and mouse from doing anything, the overriding command is: CTRL + ALT + DELETE
Basically just put BlockInput(1) at the start which will stop all keyboard/mouse from functioning
Then at the end put BlockInput(0) which releases control and allows you to do what you want.
60 Second BlockInput
BlockInput(1)
$timer = 60
For $i = 1 To $timer Step +1
Sleep(1000)
$Coords = MouseGetPos()
ConsoleWrite($timer - $i & " seconds Remaining" & #CRLF)
TrayTip("Keyboard & Mouse Frozen", $timer - $i & " seconds Remaining", 1)
ToolTip($timer - $i & " seconds Remaining", $Coords[0], $Coords[1], "Keyboard & Mouse Frozen")
Next
BlockInput(0)
I added notifications using ConsoleWrite, TrayTip and ToolTip just so that it doesn't freeze and confuse you.
Psst: This bit of code is fantastic for when you want to clean a keyboard without unplugging it or turning the computer off :P

Related

Vim command to go past a closing ) } ] " ' without pressing right arrow?

I have this problem every time I use a ( or any of " ' { [. I have plugin that automatically closes it by corresponding ) " ' } ] but I am stuck inside the parenthesis or inside double quotes
String s="I completed typing the string but my cursor is stuck right here |";
I want exit the enclosure by pressing something for all. In VScode I can press the same symbol if my cursor is right behind it and it gets past the enclosure or by pressing tab
I can exit the enclosure without reaching for right arrow
If your plugin is 'jiangmiao/auto-pairs' it has a variable called g:AutoPairsShortcutJump you can set as you want or use the default tha is Altn.
" Jump outside '"({
" -> default Alt-n
if !exists('g:AutoPairsShortcutJump')
let g:AutoPairsShortcutJump = '<A-l>'
endif
Note: If your cursor it close to the end atom you can just repeat that one to jump outside. For example:
Let's supose the character `|' represents your cursor
(|)
Just press closing parenthesis will jump outside

Running multiple parallel sqlplus connections for a certain period of time in bash

I have this code that creates 20 parallel sqlplus instances, doing some queries and exits:
#!/bin/sh
for i in $(seq 1 20);
do
echo "CREATE TABLE table_$i (id NUMBER NOT NULL);
select * from table_$i;
! sleep 30
select * from table_$i;
! sleep 30
DROP TABLE table_$i;" | sqlplus system/password &
done
wait
I need to adjust this code if possible so it would run for an hour with the following conditions:
Always stay on 20 connections, if one sqlplus instance is closed (Finished it's process) another one should open, i need to maintain a certain amount of connections for X amount of time.
Is there anything i can add to this code that will achieve what i need?
For looping during an hour, see https://stackoverflow.com/a/22735757/3220113
runsql() {
i="$1"
end=$((SECONDS+3600))
SECONDS=0
while (( SECONDS < end )); do
# Do what you want.
echo "CREATE TABLE table_$i (id NUMBER NOT NULL);
select * from table_$i;
! sleep 30
select * from table_$i;
! sleep 30
DROP TABLE table_$i;" | sqlplus system/password
sleep 1 # precaution when sqlplus fails, maybe wrong password
done
}
for i in $(seq 1 20); do
runsql $i &
done
wait
Explanation:
The main loop at the bottom starts the function runsql 20 times in the background.
The function runsql could use $1 everywhere, I copy it to i for code that looks like the original.
SECONDS is a counter that is changed every second by the shell, so we do not need to call date.
3600 is an hour.
Inside (( .. )) you can do math without $ in front of variables.

Create interrupt in bash by keys like ENTER Or ESC

I need to know is it possible to interrupt a bash script using keys like ESC or ENTER? By sending SIGINT /CTRL + C I am able to do, but due to some reasons(Check note in the last line) I cannot use CTRL +C. So I need to have some custom way to cause an interrupt.
In other terms: In following script, cleanup function is called when CTRL + C is pressed. Now need to modify this behavior so that cleanup function should be called when some keys like ENTER OR ESC is pressed.
cleanup() {
#do cleanup and exit
echo "Cleaning up..."
exit;
}
echo "Please enter your input:"
read input
while true
do
echo "This is some other info MERGED with user input in loop + $input"
sleep 2;
echo "[Press CTRL C to exit...]"
trap 'cleanup' SIGINT
done
Query:
Is it possible to use custom keys for causing interrupts in bash?
If possible, how to achieve it?
Note:
Reason: This script is called from another C++ program which has its own trap handling. So the trap handling of this script is conflicting with the parent program and ultimately the terminal is getting hung. In my organization that program's code is frozen so I cannot change its behavior. I have to tweak this child script only.
Here is a dirty trick which is doing my work just fine. read and case statement options are the key. Here I am timing out read command so that while true continues unless esc or enter is pressed.
cleanup() {
#do cleanup and exit
echo "Cleaning up..."
exit;
}
exitFunction()
{
echo "Exit function has been called..."
exit 0;
}
mainFunction()
{
while true
do
echo "This is some other info MERGED with user input in loop"
IFS=''
read -s -N 1 -t 2 -p "Press ESC TO EXIT or ENTER for cleanup" input
case $input in
$'\x0a' ) cleanup; break;;
$'\e' ) exitFunction;break;;
* ) main;break;;
esac
done
}
mainFunction
Following works ^M for ENTER and ^[ for ESC but may
stty intr ^M
stty intr ^[
but after cannot use ENTER
to restore default
stty intr ^C
After comment, as the shell is interactive what about asking to continue instead using trap, also clean can be done in special EXIT trap.
How do I prompt for Yes/No/Cancel input in a Linux shell script?
or yet another solution using select
echo "Do you want to continue?"
PS3="Your choice: "
select number in Y N;
do
case $REPLY in
"N")
echo "Exiting."
exit
;;
"Y")
break
;;
esac
done
# continue

Bash Shell - problems with quoting

I have a problem in this line:
--description=\""$(<$varLeer/media/festplatte/txt/$varDesc)\""
I want it to get out the following:
--description="$(<$varLeer/media/festplatte/txt/$varDesc)"
But how do I get it that it does not "make use" of the letters "$(< and )" ?
I hope you understand what I mean. I read this tutorial (http://wiki.bash-hackers.org/syntax/quoting) but I don't understand how I can write down the "$(< and the )" without the shell using it "as Code".
To get maybe a bit clearer, I want to get the second code to be shwon but with the "$(< )" but marked as "real code".
What I tried is this - but it did not work:
--description=\"$(<"$varLeer/media/festplatte/txt/$varDesc\")"
//EDIT: Lets be much clearer at what I want to do.
There is a phyton script called "youtube-uploader" (https://code.google.com/p/youtube-upload/wiki/Readme). Now that I don't have to write "youtube-upload ....... INSERT VERY MUCH HERE ;)" every video I want that the uploaded parts get their title, description etc automatically. My idea was to just open my ytscript.bash with nano, edit the first top variables and then just do "sh ytscript.bash", insert my password and relax.
The part would be +1 every time the loop is used and with this there is automatically an own fitting title for every part. Here is my code so far:
#!/bin/bash
# Variablen
varSpielart="Lets Play: "
varSpielname="Diablo 3 "
varParttext="- PART "
varStartpart=1
varEndpart=2
varExtras=" [PS4][1080p]"
varKategorie=Games
varDesc="lpd3desc.txt"
varDateiname=lpd3
varDateiendung=.m4v
varKeywords="ps4, spieleule, piupload"
varPlaylist="UNDEFINIERT"
varAnzahlparts=`expr $varEndpart - $varStartpart`
varLeer=" "
echo "Gebe dein Passwort ein!"
read varPasswort
echo YT-UPLOAD: BEGINNE NEUEN UPLOAD
echo YT-UPLOAD: SPIEL $varSpielname
echo YT-UPLOAD: ANZAHL PARTS: $varAnzahlparts
varDurchgang=$varStartpart
while [ $varEndpart -gt $varDurchgang ]
do
cd youtube-upload
youtube-upload --email="email#email.de" --password=$varPasswort --private --category=$varKategorie --title=\""$varSpielart$varSpielname$varParttext$varDurchgang$varExtras\"" \
--description=$(<$varLeer/media/festplatte/txt/$varDesc) \
/media/festplatte/upload/$varDateiname"p"$varDurchgang""$varDateiendung &
varDurchgang=`expr $varDurchgang + 1`
echo Durchgang: $varDurchgang
echo Entpart: $varEndpart
echo Startpart: $varStartpart
echo Anzahlparts: $varAnzahlparts
done
The automatically title works like a charm (except giving me a " at the start and the end of the title on youtube.com without me wanting it! :( ). The description on youtube.com only gets a "" in it with the first answer under this question.
Try single quotes:
--description='"$(<$varLeer/media/festplatte/txt/$varDesc)"'
Try this
temp='$(<'$varLeer'/media/festplatte/txt/'$varDesc')'
--description=$temp

Trying to insert text in between quotes on a telnet script

Sorry new to coding Applescript so any help is appreciated.
I'm trying to create a script that pastes text from clipboard into the middle of a telnet command. The output needs to be in the same window and look kind of like this:
I8,A,001
Q102,024
q448
rN
S4
D15
ZT
JF
O
R71,0
f100
N
B264,65,2,UA0,2,4,56,B,"100000000045"
A203,82,2,1,2,2,N,"xxxxx"
P1
The quoted 12 digit number on line 13 is what I need to insert.
This is what I've coded so far but it's not working:
tell application "Terminal"
do script "telnet xxx.xxx.xx.xx xxxx"
delay 1
do script "I8,A,001" in window 1
do script "Q102,024" in window 1
do script "q448" in window 1
do script "rN" in window 1
do script "S4" in window 1
do script "D15" in window 1
do script "ZT" in window 1
do script "JF" in window 1
do script "O" in window 1
do script "R71,0" in window 1
do script "f100" in window 1
do script "N" in window 1
do script "B264,65,2,UA0,2,4,56,B,\""
tell application "System Events"
tell application process "Terminal" in window 1
keystroke "v" using {command down}
end tell
keystroke "\""
keystroke return
do script "\"A203,82,2,1,2,2,N,\"xxxxx\""
do script "P1"
keystroke return
end tell
end tell
As soon as I try to use Command V to paste it exits the Terminal window and pastes whats on the clipboard on the script instead and it wont let me tell it to stay in Terminal window 1.
You do not need to use command-v to get the clipboard contents into your Terminal window. Applescript can get the clipboard and then you just add it to the other part of your string before "do script". Something like this works... of course you don't need the first line of the code because the clipboard should already have that value.
set the clipboard to "100000000045"
set t1 to "B264,65,2,UA0,2,4,56,B,\""
set t2 to the clipboard
set t to t1 & t2 & "\""
do script t in window 1
This is what I ended up using to get it to work in case anyone else needs it:
tell application "Terminal"
do script "telnet xxx.xxx.xx.xx xxxx"
delay 1
do script "I8,A,001" in window 1
do script "Q102,024" in window 1
do script "q448" in window 1
do script "rN" in window 1
do script "S4" in window 1
do script "D15" in window 1
do script "ZT" in window 1
do script "JF" in window 1
do script "O" in window 1
do script "R71,0" in window 1
do script "f100" in window 1
do script "N" in window 1
set t1 to "B264,65,2,UA0,2,4,56,B,\""
set t2 to the clipboard
set t to t1 & t2 & "\""
do script t in window 1
do script "A203,82,2,1,2,2,N,\"xxxxx\"" in window 1
do script "P1" in window 1
end tell
Thanks for the help regulus!

Resources