Make Logitech script alt tab - random

Trying to get my random mouse clicker script to Alt tab randomly to another window and follow the first random click, then randomly alt tab back. This is the script im using currently.
EnablePrimaryMouseButtonEvents(true);
function OnEvent(event, arg)
if IsKeyLockOn("capslock")then
if IsMouseButtonPressed(5)then
repeat
PressMouseButton(3)
Sleep(math.random(2000, 940000))
ReleaseMouseButton(3)
until IsMouseButtonPressed(4)
end
end
end
Also its not the end of the world but i cannot shut this script off, with mouse button 4 which is what i wrote it to do. im fairly new to LUA so excuse my noobness. Thanks.
I keep getting script errors when adding another press function

The script checks button4 state very rarely - you should keep button4 pressed for 940 seconds to be sure the script turned off.
To be more responsive, the script should run wait-a-bit + check-button4 loop:
EnablePrimaryMouseButtonEvents(true);
function OnEvent(event, arg)
if IsKeyLockOn("capslock")then
if IsMouseButtonPressed(5) then
repeat
PressMouseButton(3)
local tm = GetRunningTime() + math.random(2000, 940000)
repeat
Sleep(10)
until GetRunningTime() > tm or IsMouseButtonPressed(4)
ReleaseMouseButton(3)
until IsMouseButtonPressed(4)
end
end
end
I don't see any attempt to Alt tab simulation in your script.
Post your code.

Related

Run an animation in Ruby while using TTS gem

What I'm trying to do is:
1) use the Ruby TTS gem to read some text.
2) while the text is being read, I want to loop through an animation.
The way I'm calling the animation is this:
def animation
i = 1
while i < 3
print "\033[2J"
File.foreach("lib/narrabot/flair_folder/#{i}.txt") { |f| puts f }
sleep(0.03)
i += 1
end
end
What seems like a quirk (or feature) of the TTS gem is that if you hit a button on your keyboard while it's running... it will replay from where you interrupted... So, when I tried to run the loop assuming I could just "play" the text, TTS essentially stuttered and didn't run the animation until it ended and then it went back to the beginning.
I just required this gem... https://github.com/grosser/parallel but am not sure how to tackle my goal.
In case you're curious -- my project is here: https://github.com/AdamWeissman/narrabot
What I'm attempting to do is use TTS to read Aesop's Fables... and while a Fable is being read... an ascii animation of a fire will run in the background. Eventually, I hope to replace the image of the fire with an ascii face (sorta like a sock puppet... the intent is to get the mouth to move in sync -- relatively -- with the speech... but that's a long way off).

How can I have a button trigger a function to move the mouse cursor on a timer in C#/visual studio?

I'm building an automatic timer system as a fun silly project for some office chums. It's end user goal is to allow end users to be away from keyboard while still simulating activity to prevent timed applications from changing their statuses to away.
I have the front end of a windows form with two buttons. ON and OFF. When I press on, I want it to begin moving the mouse in 1 minute intervals for a moment. (or click maybe.) and when I select off it stops the action.
I've never really coded much before (I've done basic python stuff so I know what an if statement is, a function, how to declare a variable etc but I've never done anything with a GUI or in c# so this is all new.)
Lastly, I would want to save/export it as an exe for distribution for slackers I mean end users to run and use.
Thanks so much for the help!
Looks like someone is trying to hack their way out to keep their PC active when away from desk :D
//programmatically move the mouse example
PointConverter pc = new PointConverter();
Point pt = new Point();
pt = (Point)pc.ConvertFromString("0, 768");
Cursor.Position = pt;
Ref

Continually track mouse coordinates

I want to continually track the mouse as it moves, or at least every 0.5 seconds:
require "curses"
include Curses
init_screen
start_color
init_pair(COLOR_BLUE,COLOR_BLUE,COLOR_WHITE)
init_pair(COLOR_RED,COLOR_RED,COLOR_WHITE)
crmode
noecho
stdscr.keypad(true)
close = false
begin
mousemask(BUTTON1_CLICKED|BUTTON2_CLICKED|BUTTON3_CLICKED|BUTTON4_CLICKED)
count = 0
while( count < 10 )
sleep 0.5
m = getmouse
winx = Window.new(7,30,10,10)
winx.keypad = true
winx.box(?|, ?-, ?+)
winx.setpos(2,3)
winx.addstr "Loop Count: " + count.to_s
winx.setpos(3,3)
winx.addstr "Mouse Position: " + m.inspect
winx.refresh
count += 1
end
refresh
ensure
close_screen
end
I think I'm close, but for some reason, getmouse is returning nill? Why is this? Does getmouse only work after an event such as a click? If so, is it impossible to continually track the mouse?
This from the ruby documentation
getmouse() click to toggle source
Returns coordinates of the mouse.
This will read and pop the mouse event data off the queue
See the BUTTON*, ALL_MOUSE_EVENTS and REPORT_MOUSE_POSITION constants
REPORT_MOUSE_POSITION appears to be key here, but I really don't know how to use these constants. getmouse(REPORT_MOUSE_POSITION) doesn't work..sorry if that's majorly nooby, but there isn't much documentation out there.
You need to add REPORT_MOUSE_POSITION to your mousemask:
mousemask(BUTTON1_CLICKED|BUTTON2_CLICKED|BUTTON3_CLICKED|BUTTON4_CLICKED|REPORT_MOUSE_POSITION)
Or perhaps just
mousemask(ALL_MOUSE_EVENTS)
Curses processes mouse clicks in the same stream as key presses. So you need to get your mouse events with getch.
In your case, I recommend setting getch to non-blocking read stdscr.timeout=0 and adding a case statement:
case getch
when KEY_MOUSE
m = getmouse
winx.addstr "Mouse Position: #{m.x} #{m.y} #{m.z}"
end
Unfortunately on my system this only reports mouse movement when I click, so you might be out of luck depending on your curses implementation/terminal.
If you aren't too afraid of C, I recommend reading the ncurses C documentation. Ruby's curses library is basically a direct translation of it.
According to the TLDP nurses documentation, you need to use REPORT_MOUSE_POSITION Asa constant in your mouse mask. Try this:
mousemask(REPORT_MOUSE_POSITION|BUTTON1_CLICKED|BUTTON2_CLICKED|BUTTON3_CLICKED|BUTTON4_CLICKED)
This tells curses to report the mouse position as an event.
See the answer to Mouse movement events in NCurses.
Mouse event reporting depends heavily on the terminal emulator (on a Mac in iTerm2, I had to "Enable xterm mouse reporting" in preferences), and on the TERM settings as described above (I had to launch ruby like TERM=xterm-1003 ruby curses_mouse.rb)
Also, you must call getch and test for KEY_MOUSE before calling getmouse. For example, if you're only interested in mouse events:
c = getch
case c
when KEY_MOUSE
m = getmouse
end
Also, add |REPORT_MOUSE_POSITION to mousemask call.

Autohotkey: multiple / contingent uses for one command

I'm working on a game design / UI project to redesign an existing game's control scheme (in this case, Trine) to use minimalistic input. I am trying to map lateral movement and the jump function to a Win8 tablet's volume buttons. Here is the basic code I am using:
Volume_Up::
Loop 5
{
Send {right down}
Sleep 50
}
Send {right up}
Return
Volume_Down::
Loop 5
{
Send {left down}
Sleep 50
}
Send {left up}
Return
This is working fairly well and is pretty responsive for moving left and right. However, the desired behavior that I want is to trigger jump (i.e. up) when BOTH buttons are depressed. For instance:
Player holds VolumeUp to move right.
Player comes to an obstacle.
Player continues to hold VolumeUp to queue right-bound movement and;
Player taps VolumeDown momentarily
Player jumps, movement continues up-and-over obstacle toward the right.
I have tried various permutations on using another script with the (Volume_Up & Volume_Down::) syntax to trigger this interaction, but that always seems to interfere with the movement commands. I think this may call for a nested If statement inside the move-left / move-right commands, to check if both buttons are depressed, but the Autohotkey documentation is not very clear and I'm unsure how to code that (I'm more of a game designer than I am a programmer). Any help would be really appreciated!
First of all, give attention to the comment from MCL. Pressing a button down 5 times and never releasing it in between does not seem to do much.
I think that you want multiple threads to be able to run at the same time.
Look up threads, but be aware about the following:
"Although AutoHotkey doesn't actually use multiple threads, it simulates some of that behavior: If a second thread is started -- such as by pressing another hotkey while the previous is still running -- the current thread will be interrupted (temporarily halted) to allow the new thread to become current. If a third thread is started while the second is still running, both the second and first will be in a dormant state, and so on."

Using a variable in a message - Lingo

Can anyone tell me if there is a way for me to use a variable within a lump of code, so that code can be looped to send messages to multiple objects?
For example, if I have 10 buttons and want each to send a variation of the same command 'sendCommandX', with X being the number of the button.
Right now I have 10 separate messages, and each button calls its own, like
on mouseUp
sendCommand1
end
on mouseUp
sendCommand2
end
Each of these 10 sendCommand# messages do the same thing, just with a different number in them.
It would be great if I could use a variable within the call, so I could have one reusable message. Like:
on mouseUp
sendCommandX (X being the number of the button clicked)
end
and then the sendCommandX could use the same variable within, like
on sendCommandX
echo "you clicked button X:
end
send the number as a parameter:
-- on Button 1
on mouseUp
sendCommand 1
end
-- on Button 2
on mouseUp
sendCommand 2
end
-- movie script!
on sendCommand which
-- use 'which' here, e.g.
put "You pressed button " & which
end
I guess your button scripts are cast member scripts?
This code would be better as a behavior, because then you'd only need one script. But it will work ok like this.

Resources