StrokesPlus Forum
                       
StrokesPlus Forum
Home | Profile | Register | Active Topics
Members | Search | FAQ
 All Forums
 General Discussion
 General Discussion
 [Solved!] To "toggle" or "repeatedly send"a key?

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

UserName:
Password:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkInsert EmailInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
AxJ Posted - 03/27/2019 : 23:42:16
Is there any way to achieve these two functions?
I'm surprised I didn't use these before on S+.
Am I missing something?
12   L A T E S T    R E P L I E S    (Newest First)
AxJ Posted - 03/29/2019 : 20:51:50
quote:
Originally posted by Rob

They are variables, just ones you don't see. ...



Oh~ Now I know where do they come from and why they are so smart!!!
Rob Posted - 03/29/2019 : 20:44:37
They are variables, just ones you don't see. Before an action (your script) is executed, they are added to the top of your script, then the whole script is executed. Snippet from the source code:
	ActionScript.append(_T("local sp_gesture_name = \"")+sTempGestureName+"\"\n");
	ActionScript.append(_T("local sp_gesture_start_x = ")+boost::lexical_cast<std::basic_string<TCHAR>>(DrawPoints[0].x)+"\n");
	ActionScript.append(_T("local sp_gesture_start_y = ")+boost::lexical_cast<std::basic_string<TCHAR>>(DrawPoints[0].y)+"\n");
	ActionScript.append(_T("local sp_gesture_end_x = ")+boost::lexical_cast<std::basic_string<TCHAR>>(lastx)+"\n");
	ActionScript.append(_T("local sp_gesture_end_y = ")+boost::lexical_cast<std::basic_string<TCHAR>>(lasty)+"\n");
	ActionScript.append(_T("local sp_wheel_delta = ")+boost::lexical_cast<std::basic_string<TCHAR>>((int)dWheelDelta)+"\n");
	ActionScript.append(_T("local gwd = sp_wheel_delta\n"));
	ActionScript.append(_T("local gnm = sp_gesture_name\n"));
	ActionScript.append(_T("local gsx = sp_gesture_start_x\n"));
	ActionScript.append(_T("local gsy = sp_gesture_start_y\n"));
	ActionScript.append(_T("local gex = sp_gesture_end_x\n"));
	ActionScript.append(_T("local gey = sp_gesture_end_y\n"));
	ActionScript.append(_T("local gbl = ")+boost::lexical_cast<std::basic_string<TCHAR>>(iBoundingLeft)+_T("\n"));
	ActionScript.append(_T("local gbt = ")+boost::lexical_cast<std::basic_string<TCHAR>>(iBoundingTop)+_T("\n"));
	ActionScript.append(_T("local gbr = ")+boost::lexical_cast<std::basic_string<TCHAR>>(iBoundingRight)+_T("\n"));
	ActionScript.append(_T("local gbb = ")+boost::lexical_cast<std::basic_string<TCHAR>>(iBoundingBottom)+_T("\n"));
AxJ Posted - 03/29/2019 : 20:41:27
quote:
Originally posted by Rob

Right, variables have scope, ....

Yes, but what are "gex" and "gey"? How do they know the last location of the mouse cursor?
I don't see any variable here. Or does it do it in the background?
quote:
You can also refactor even further if you want:
acConsumePhysicalInput(1)
acMouseClick(acGetMouseLocationX(), acGetMouseLocationY(), 2, 1, 0)
acConsumePhysicalInput(0)
:)


Nice, I like that in this case. Thanks!
Rob Posted - 03/29/2019 : 20:31:55
Right, variables have scope, otherwise all variables everywhere would just keep using up more and more memory, so they have a defined lifetime. But passing them into another function causes the next function to copy them, and again the lifetime for the copies are only within that next function.

You can also refactor even further if you want:
acConsumePhysicalInput(1)
acMouseClick(acGetMouseLocationX(), acGetMouseLocationY(), 2, 1, 0)
acConsumePhysicalInput(0)
:)
AxJ Posted - 03/29/2019 : 19:56:15
quote:
Originally posted by Rob

1) gex and gey are only in scope within the action. S+ basically prepends something like this to the action's script before executing:


Oh, I see. I get it. And I got it works too.
So, basically, "gex" and "gey" can't be used in this situation(?).
And it's only one method that using variables either within the script or before the script and then passes them into the script.

quote:
Note you might want to change "keydown" to "mousedown" or something, ...


Oh, right, I've changed them. Thanks for the heads-up.

quote:
2) Windows requires mouse coordinates when invoking a click event, so they have to be there. You can use acGetMouseLocationX/Y ...


Ah~~ I forgot the "up" command can be false.
The mouse dragging action is pretty simple then.

--
local mousex = acGetMouseLocationX()
local mousey = acGetMouseLocationY()
acConsumePhysicalInput(1)
acMouseClick(mousex, mousey, 2, 1, 0)
acConsumePhysicalInput(0)

--

Thanks for the help again!
Rob Posted - 03/29/2019 : 07:44:03
1) gex and gey are only in scope within the action. S+ basically prepends something like this to the action's script before executing:
local gex = 123
local gey = 456
(etc)
You could update your function to accept those coordinates:
function ContinousMouseClick(x, y)
	while(acGetNumberVariable("keydown") == 1) do
		acMouseClick(x,y,2,1,1)
		acDelay(10)
	end
end
And in your action call it, passing them into the function, e.g. ContinousMouseClick(gex, gey)

Note you might want to change "keydown" to "mousedown" or something, just so if you had a keydown and mousedown script running at the same time, they wouldn't conflict and lead to unexpected results.

2) Windows requires mouse coordinates when invoking a click event, so they have to be there. You can use acGetMouseLocationX/Y to get the current position and pass those in. And for something like a drag, it would need to look somewhat like this:
acConsumePhysicalInput(1) --Prevent your own mouse movement
acMouseMove(x, y) --move to the starting location, unless you use acGetMouseLocationX/Y of course
acDelay(5)
acMouseClick(x, y, 2, 1, 0) --Only send the down event, not the up
--TBD: This would move the mouse 100 from X and 100 from y
x = x + 100
y = y + 100
acMouseMove(x, y) 
acDelay(5)
acMouseClick(x, y, 2, 0, 1) --Only send the up event
acConsumePhysicalInput(0) --Allow physical mouse input again

AxJ Posted - 03/29/2019 : 05:42:10
quote:
Originally posted by Rob

So something like this:

In the Global Lua Tab:
function ContinousKeyPress(char)
	while(acGetNumberVariable("keydown") == 1) do
		acSendKeys(char)
		acDelay(10)
	end
end


Hi, thanks for your script. It works great so far!
And I edit some lines for using mouse click:

--
In the Global Lua Tab:
function ContinousMouseClick()
	local mousex = acGetMouseLocationX()
	local mousey = acGetMouseLocationY()
	while(acGetNumberVariable("keydown") == 1) do
		acMouseClick(mousex,mousey,2,1,1)
		acDelay(10)
	end
end

--
It works fine to me. But I have two questions:

1) In my mouseclick script, if I use "acMouseMove/Click(gex,gey)," the mouse cursor always goes to (0,0). May I ask why is that? The script looks like this:

--
In the Global Lua Tab:
function ContinousMouseClick()
	while(acGetNumberVariable("keydown") == 1) do
		acMouseClick(gex,gey,2,1,1)
		acDelay(10)
	end
end

--
2) Is it possible to perform a mouseclick action without designating a specific mouse location for a "mouse dragging" action?
Rob Posted - 03/28/2019 : 22:47:50
So something like this:

In the Global Lua Tab:
function ContinousKeyPress(char)
	while(acGetNumberVariable("keydown") == 1) do
		acSendKeys(char)
		acDelay(10)
	end
end

In The Action:
if acGetNumberVariable("keydown") == 1 then
	acSetNumberVariable("keydown", 0)
else
	acSetNumberVariable("keydown", 1)
	ContinousKeyPress("c")
end

First time you perform the action, it starts pressing the "c" key. Next time you execute the action it sets a variable that the function examines each time it loops (in the while statement) and stops if it's no longer 1.
AxJ Posted - 03/28/2019 : 18:05:46
Mostly use them in games and the web browser(Chrome)
1) In games: toggle "C" key to crouch or "Q" key to aim

2) In Chrome: To delete 100+ download history items by a specific result of the search filter

Hope this helps!
Rob Posted - 03/28/2019 : 09:42:48
Maybe it would help to describe the scenario you're trying to accomplish.
AxJ Posted - 03/28/2019 : 09:39:59
OH, man, I completely lost. But I'll try to figure it out. XD
Rob Posted - 03/28/2019 : 09:22:13
I mean, you can make a loop to send the key over and over, but you'd also need a way to signal when it should stop. This could be accomplished in the same action, using something like acSetNumber and acGetNumber, so the first time you store a value and the next time the action executes it checks the number value to signal it was already toggled and to instead stop. I think this might need a function in Global Lua that loops and checks the number value. I've honestly only been using StrokesPlus.net for the last year and a half, so I'm really starting to get rusty with StrokesPlus scripts :P

StrokesPlus Forum © 2011-2018 Rob Yapchanyk Go To Top Of Page
Snitz Forums 2000