Forge Keystrokes Mod

0 views
Skip to first unread message

Cora Hickel

unread,
Aug 5, 2024, 3:37:30 AM8/5/24
to marbcleavinto
ButI dont know how to follow a player's keystrokes. For example, currently I have setup a system, that adds the players to a list who do a certain thing, but I am really unsure how to follow that specific player's key stuff.

Im not expecting the practical work-out, but I do really like to see some theory what steps I should follow. Not in great detail or anything, but just something that you guys point me in the right direction.


You need to use a custom packet for that - each time the client presses your key of interest, you need to read that on the client (eg in a tick handler), send a packet to the server, then have the server process the packet.


The first is to use one of the many Forge registries or hooks, to add custom blocks, items, or get called when particular things happen. This is very common. Unfortunately the documentation is a bit patchy so it's not always easy to know what's available. A typical strategy I use is to identify an item or block or whatever that does something similar to what I need. Then I'll look at the vanilla code and trace it through until I figure out how it works, and usually I will stumble over a forge hook or event along the way.


The second strategy which is harder and less robust is to override an existing vanilla class and replace any references to it from other vanilla code. For example, you can overwrite GameSettings.keyBindForward with your own class derived from KeyBinding. This is usually not necessary and is often not possible.


A fourth strategy you will hear occasionally is reflection / ASM. I would avoid this like the plague because it is fragile and very hard to debug. I had my fill of self-modifying code back in my days of programming assembly and am not keen to go back!!


Reflection is a powerful type of code to make mods compatible between each other without dependency. A practical example is the Forge annotations, those are loaded with reflection. Manipulating classes at runtime, that is the goal of reflection.


ASM is an extremely powerful tool (to break everything without knowing ) relying on bytecode (read: manipulating lines of code, at an "internal" level). If you master it, you can change as much things as Forge without shipping Minecraft code.


Well, the difference to my mind is that the second strategy (overriding a single method) is less likely to be broken if the vanilla classes are updated, compared with overwriting the entire class with a modified copy, or god forbid relying on the bytecode being the same. But I agree it's not as robust as using the forge methods.


I agree with you that both ASM and reflection are very powerful tools in the hands of the Java uebercoder, unfortunately those ranks don't include me :-) I also doubt that the extra flexibility is really necessary unless you're doing forge-like magic, i.e. you need to link in other classes at runtime and you don't know in advance what they are. (I understand the ethical objections against shipping even small parts of the Minecraft code, to be honest I really doubt that the Mojang folks would care that much given how long Forge was doing it).


At the end of the day I prefer to use chainsaws for cutting trees rather than trimming my nails, and I struggle enough with getting my code to work as it is without trying to get my mind around the extra runtime complexity :-). Maybe once I've got a couple years Java experience I'll think differently...


I am using a Win7 computer that drops its mapped drive connections each time I reboot it. (Well known problem apparently, I have found no fix so far). So I added the drive path (\servername\foldername) as one of the keepass entries' URL so that I can just click it to open a Windows Explorer window to that specific folder. However, that step does not actually map the drive to a letter (in my case, 'H') - a mapping which would be nice to have for many reasons.


I was hoping that I could use the "Auto-type" override field like a MACRO to add several keystrokes that would run (via CTRL-ALT-A or whatever) but so far no luck. I would need something like an ALT-T (to open "tools"), N (to pick "map network drive"), SHIFT-TAB, H, etc.


The auto-type sequences for Alt-T then N is %TN. You can use parentheses to improve readability e.g (%T)N. A custom global auto-type (Ctrl-Alt-A) that would open the 'Map Network Drive' dialog, provided that Windows Explorer has the focus, and is open to the 'My Documents' folder is:


To use Global Auto-Type, the Target Window must match the Window Title of Windows Explorer. Because this title is variable (it tracks the directory shown in Windows Explorer) you must initiate the auto-type from the same Window every time or use regular expressions in the Target window field of a custom auto-type sequence to match a range of Windows Explorer window titles (alternatively define multiple custom auto-type sequences).


To open Windows Explorer to a specific directory, use a command line in the Entry's URL field and double click on that URL, e.g. the URL "cmd://explorer /root,C:\%USERPROFILE\Documents" (without the quotes) would open a new Windows explorer window to the 'My Documents' folder.


Sound Forge Audio Studio (AS) does not have a Custom Keyboard shortcut tool like Sound Forge Pro.

However, custom commands can be added manually to the SF keyboard data file.. if the process exists and the code is known. What commands and which keys would you like to use?.

I can check it out when I get around to installing AS-16 to see which are possible. I assume the basic code, data file name and path will be similar to AS-15.


As I stated, custom keyboard shortcuts cannot be added to Audio Studio without hacking a data file. and btw, hacking the file is not as dangerous as focking around with registry. If there are conflicts, is easy to reinstate the default. Finding unused key combos may be difficult though. Are there specific ksy combos and you wish it use. , most need to Ctrl, Shift, Alt of combo of as a exicute header.

That said, I suspect most on @samuel-mattos' list are possible. I will look into it as time permits.


"space bar and F12 play/pause instead of play/stop". I'm not sure what you are supposed to do with the F12. Does that mean to press the space bar and F12 at the same time to switch between the two options, play/pause or play/stop? I tried doing that and it didn't make any change.


What I was hoping for was a quick key shortcut for the function of switching between space bar play/pause and space bar play/stop. I use these two options a lot and every time I want to go from one to the other it requires opening the preferences dialog and checking or unchecking the box.


It can be a bit confusing @DGN, I will try to explain, Firstly, F12 key is basically an unimportant factor, so forget about it.

The default Play/Stop behavior is using the Spacebar to stop/start playback .. When playback is stopped using the spacebar, the cursor will always return to the original position on timeline. pressing the Spacebar again resumes playback from that original point). In the same default mode, the Enter key is Play/Pause, which suspends playback and puts the cursor to the point you pressed the Enter key. Playback will resume from that point when the Enter key is pressed again.

When the "Spacebar and F12 Play/Pause instead of Play/Stop", is check-marked in the in "Options> Preferences> General" menu, it just reverses the above key functions: The Spacebar becomes Pause/Play and Enter becomes Play/Stop.


I was very happy to hear about the Enter = Play/Pause option but I just tried using the Enter key to play pause and the cursor went back to the place I had clicked on with my mouse just like the spacebar does. So now I'm wondering if there is a setting that needs to be changed. I always assume operator error so I'm hoping for that. Changing the play pause setting in preferences just causes the Space Bar and Enter to play/pause instead of Play/Stop.


FWIW, you can add custom timeline positions with "Edit> Go to". Markers are very useful as well ("M" key) Clicking Ctrl+ Left or Right (arrow keys) will move the cursor to the previous or next Marker.


I do not think a sub-menu check-box setting can assigned a shortcut. The closest I can get to it is a shortcut to: "Options> Preferences> General".

Most commands in the regular menus can have a keyboard shortcut created though.


I was looking at writing a plugin to map the basic Emacs keystrokes (yes, I'm one of those) to Notepad++. How hard could it be? I used SCI_ASSIGNCMDKEY to make new shortcuts. And it works for some keys and not others. Here is some example code for ^A and ^B:


It seems that the newly installed shortcuts do not override the menu accelerators. Which means I must either remove them which is very awkward and is probably not considered "playing nicely with others", or capture the keystroke earlier on.


You'd probably be better off reassigning the shortcuts in the shortcut mapper (Scintilla commands tab), and then offering the shortcuts.xml as the Emacs key bindings. I suspect N++ subclasses Scintilla to steal the keystrokes before scintilla sees them, which is why C-F is taken by N++ first. However, you'll only be able to do the single key press combinations, chords like C-x C-f you won't obviously be able to map. One way to achieve that would be to subclass Scintilla in your plugin, then you can steal the key codes, and potentially support the chords.

3a8082e126
Reply all
Reply to author
Forward
0 new messages