Page 1 of 1

SHIFT key stuck, release?

Posted: Sat May 15, 2010 10:22 pm
by rock5
There is a point in my script where it opens a mail box with a mouse click. I have my own harvest function that, if it fails, turns 90 degrees and tries again. It repeats this until successful.

The PC is unattended. Sometimes when I check on it, I find it continuously scanning for the mail box but not turning. When I opened a file and click in it, it selects text as if shift is being pressed. If I tap shift it releases and the bot then turns between scans. I have noticed it hasn't opened the giftbags either so suspect maybe it is causing the bags not to open as well.

I suspect the shift is being locked when changing characters.

Is there a way to fix this or at least a command to release the shift key?

Re: SHIFT key stuck, release?

Posted: Sat May 15, 2010 11:15 pm
by Administrator
I guess you could manually press (not just release, as this sometimes doesn't work as you'd expect) any problematic keys.

Code: Select all

keyboardPress(key.VK_SHIFT);
I'm not entirely sure this is a problem with MicroMacro or the bot, though. I've noticed on several occasions that keys such as CTRL, SHIFT, or ALT get stuck and stay stuck until i physically press that key. This happens even when MicroMacro is not open.

Re: SHIFT key stuck, release?

Posted: Sun May 16, 2010 4:26 am
by rock5
Administrator wrote:I guess you could manually press (not just release, as this sometimes doesn't work as you'd expect) any problematic keys.

Code: Select all

keyboardPress(key.VK_SHIFT);
I'm not entirely sure this is a problem with MicroMacro or the bot, though. I've noticed on several occasions that keys such as CTRL, SHIFT, or ALT get stuck and stay stuck until i physically press that key. This happens even when MicroMacro is not open.
The thing is I'm not even touching the computer. Anyway, I'll try the above.

Regardless of the cause, I'm fairly certain the shift key interfered with turning. I'm not so sure if it's the cause of the bags not opening. Do you know if the shift key would cause problems with opening bags?

Re: SHIFT key stuck, release?

Posted: Sun May 16, 2010 4:17 pm
by Administrator
Could be. It could cause any number of strange occurrences. Have you checked the hotkeys for opening or closing bags?

Re: SHIFT key stuck, release?

Posted: Sun May 16, 2010 4:38 pm
by rock5
Administrator wrote:Could be. It could cause any number of strange occurrences. Have you checked the hotkeys for opening or closing bags?
Sorry I meant the giftbags.

Anyway, since I added a manual opening of the first gift bag in the first script, I haven't had any trouble with that.

With the mailbox, I tried the command above. I inserted it after every scan but it still doesn't turn. I still discover it scanning but not turning. I found, though, that I don't have to tap shift to release it. All I have to do is pause with the END key then continue with the DELETE key. It then immediately turns and scans until it finds the mail box.

Maybe I should try player:faceDirection(dir). Maybe that will be more reliable.

Re: SHIFT key stuck, release?

Posted: Sun May 16, 2010 5:33 pm
by Administrator
When pausing the script, it is using a callback which is releasing the SHIFT key (among others). It's pretty much the same thing.

Re: SHIFT key stuck, release?

Posted: Mon May 17, 2010 3:07 am
by rock5
I've discovered, even with simple small tests, that player:turnDirection() and player:faceDirection() don't work. It just twitches and doesn't turn.

While looking at player:faceDirection I got the idea to try camera:setRotation(). This works perfectly and I find it a lot more reliable. Also it doesn't turn physically while scanning, which looks less bottish.

So I have a suggestion for player:target_NPC(). Can you change the turning behavior so that it only turns the camera view?

The benefits are;
1. More reliable.
2. Less bottish.
3. I suspect it might fix the problem of not turning when trying to target an npc while mounted.

Re: SHIFT key stuck, release?

Posted: Mon May 17, 2010 5:26 pm
by Administrator
Are you saying you tested using camera:setRotation() in CPlayer:target_NPC(), or that you used camera:setRotation() inside CPlayer:setDirection()? Does it work OK if you have QUICK_TURN enabled? Does it break gathering?

Re: SHIFT key stuck, release?

Posted: Mon May 17, 2010 10:44 pm
by rock5
Administrator wrote:Are you saying you tested using camera:setRotation() in CPlayer:target_NPC(), or that you used camera:setRotation() inside CPlayer:setDirection()? Does it work OK if you have QUICK_TURN enabled? Does it break gathering?
I don't like to modify the original functions.

What I did is create a function like this. It makes 100% sure that it opens the frame, be it a mailbox, or bulletin board or speakframe.

Code: Select all

function SureHarvest(_objID, _frameName)
	sendMacro("CloseAllWindows()")
	local ang = 0 -- Start angle
	repeat
		player:harvest(_objID,true) -- scan for object
		camera:setRotation(ang)
		ang = ang +1.57 yrest(1000) -- 90 degree turn
	until RoMScript("_G['".._frameName.."']:IsVisible()")
	yrest(2000)
	return true
end
Now I know this is not the best of code (infinite loop and doesn't start with current angel) but the point is camera:setRotation works. When I used faceDirection or turnDirection they didn't turn. Seeing as this worked so well for me in this situation I thought it would be better for target_NPC as well (for the reasons stated above). I haven't actually made any changes to target_NPC. I always use quick turn on.

I'm not asking you to change Harvest as it is fine the way it is. Rotating while harvesting would be impractical. All I'm suggesting is changing the turning method for target_NPC to camera:setRotation as you don't need to physically turn to target an NPC and you get the benefits stated in my previous post.

Re: SHIFT key stuck, release?

Posted: Tue May 18, 2010 2:13 pm
by rock5
Ok, I did the test for you. In the target_NPC function I changed the self:turnDirections with camera:faceDirection.

I changed this;

Code: Select all

		if( counter == 2 ) then
			self:turnDirection(-45);
		elseif( counter == 3 ) then
			self:turnDirection(90);
		elseif( counter > 3 and  counter < 9) then
			self:turnDirection(45);
		elseif( counter > 8 ) then
			break;
		end
to this;

Code: Select all

		if( counter == 2 ) then
			scanDirection=scanDirection - math.pi/4
		elseif( counter == 3 ) then
			scanDirection=scanDirection + math.pi/2
		elseif( counter > 3 and  counter < 9) then
			scanDirection=scanDirection + math.pi/4
		elseif( counter > 8 ) then
			break;
		end
		camera:setRotation(scanDirection)
I also initialized scanDirection near the other 2 variable initializations;

Code: Select all

	local found_npc = false;
	local counter = 0;
	local scanDirection = self.Direction
It works perfectly. It even works when mounted. QUICK_TURN has no effect on it and it looks less like a bot.

I highly recommend you use this.

Re: SHIFT key stuck, release?

Posted: Tue May 18, 2010 4:33 pm
by Administrator
Alright, thanks. It's been committed.