Originally Posted by
PhoenixVip1337
thank you, that's what I'm doing now; but I think it's not very good to spam one key on every point ^^
Just figured out which key you need to press and hold them down until you see you are a the right angle or position, by this you do not have to spam one key.
The only problem here are that if the window lose focus the key stopped being pressed, so you need a work around there.
This is my move function
Code:
if (isBehind)
{
HoldKeys.Add(dot > 0.5 ? Keys.Left : Keys.Right);
}
else
{
if (dot > dotProduct)
{
HoldKeys.Add(Keys.Left);
}
else if (dot < -dotProduct)
{
HoldKeys.Add(Keys.Right);
}
}
if (distance > moveModel.Distance)
{
HoldKeys.Add(Keys.Up);
}
else if (moveModel.Retreat)
{
if (distance < moveModel.MinDistance)
{
HoldKeys.Add(Keys.Down);
}
}
public void UpdateWalk()
{
var handle = WindowHandle;
foreach (var key in HoldKeys.Where(x => !lastKeys.Any(c => c == x)))
{
WinAPI.PostMessage(handle.ToInt32(), WinAPI.WM_KEYDOWN, (int)key, 0);
}
foreach (var key in lastKeys.Where(x => !HoldKeys.Any(c => c == x)))
{
WinAPI.PostMessage(handle.ToInt32(), WinAPI.WM_KEYUP, (int)key, 0);
}
lastKeys = HoldKeys.ToArray();
}