Comments (3)
This kind of reminds me of a problem that I had at the start of my famebot when I was trying to send keystrokes thru a timer to simply move my character around. I noticed that I could send "D" for example to move right, but if I stopped sending D and tried A right after it wouldnt work.
Turns out I needed to release "D" in order to send "A" (same for W and S)
Idk if this has anything to do with your code / if you release the keystrokes but maybe when it loses focus, the release flag isnt raised for that key?
The keyup flag that I used in keybd_event was
public const int KEYEVENTF_KEYUP = 0x0002
The thing is, keybd_event required window focus while SendMessage can do it in the background. But I think it would be worth trying.
What I would do was release every key at the end of each "step" in my famebot just to be safe. So I released W A S D even if they weren't pressed before, because releasing a key has no side-effects, but can solve problems.
from famebot.
Discussion
The movement system uses SendMessage
with the virtual key codes for WM_KEYUP (0x0101)
and WM_KEYDOWN (0x0100)
.
I don't think the issue is related to releasing a key before pressing the next one. If you look at the CalculateMovement
code, you can see it always releases the appropriate key before pressing the next one. E.g. if A needs to be pressed, D_PRESSED
will be set to false before A_PRESSED
is set to true.
I think the issue is that when the key properties (W_PRESSED, A_PRESSED, ...
) are set, the code to press/release the key is only run if the new state of the key is different to its current state. E.g. if A_PRESSED
is false and you try to set it to false, no SendMessage
will occur.
I implemented this because I was concerned that calling SendMessage
many times could have performance impacts, but now that the bot has been out for a long time and no one has reported performance issues, it's probably safe to say it's a very cheap operation. Changing the properties to always call SendMessage
regardless of the key's current state may not fix the issue, but considering the almost non-existent performance impact, it's probably a good idea.
It's also very unusual that some of the keys still work correctly (S and D as mentioned before) but the fact that W in particular stops working gives a lot of insight because (when testing in the Nexus) it is the key which is pressed when the Window loses focus.
This makes me think that the cause could be that when the window loses focus, any keys which were pressed get released by Windows, but that isn't reflected in the code. E.g. Windows releases the W key, but because W_PRESSED
is still true, the bot thinks it is still pressed and doesn't call SendMessage
again.
Results
After some research, I am fairly confident that the way I implemented the key properties is the cause of the issue. Windows sends the WM_KILLFOCUS
message to a window "immediately before it loses the keyboard focus." I am guessing that this releases any pressed keys, but because this event isn't acknowledged by the bot, it still thinks the W key is pressed and so it doesn't call SendMessage
to press the key again.
Solution
Either:
- Change the key property implementation to just always call
SendMessage
- Detect when the window loses focus and set all keys to false.
I will start on a fix when I finish work, but feel free to make a pull request if you want to have a stab at fixing it 😊
(In Core/Plugin.cs, look at the code in the #region Keys
for the key press properties)
from famebot.
Fixed. See commit 944e188 for details.
from famebot.
Related Issues (20)
- Keystrokes arent being sent to client even though famebot says keys are being pressed HOT 3
- [Request] Checkbox to toggle Enemy Avoidance HOT 3
- [Request] Some kind of Discord implementation HOT 2
- [Request] smart autoloot
- Nexus changed now it just goes to corner of nexus please fix HOT 2
- FameBot Not Moving HOT 8
- [Request] Make auto-aim a requirement for all bots HOT 1
- Trying to edit? HOT 3
- Nexus positions need updating HOT 7
- Client disconnected HOT 4
- Locations need an updating. HOT 1
- Trying to move to a realm below the realmposition causes incorrect behaviour
- Bot positioning needs updating HOT 2
- Question about Realm bots in general HOT 3
- Nexus positions need updating HOT 1
- If the bot reconnect's to a same dungeon > kicked to char list. HOT 2
- Nexus positions need updating
- Lag HOT 6
- Nexus positions need updating HOT 1
- Nexus positions need updating HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from famebot.