Page 1 of 1

Patch: WASD patch v0.1

Posted: 01 Aug 2017 11:39
by zzoru
Deprecated..?
You can use another patch OpenTTD-ScrollHotkey Patch v0.1 (https://github.com/zzoru/OpenTTD-TinyPa ... roll.patch)

OpenTTD-WASD Patch v0.2
For my HHKB2, I want to play OpenTTD using wasd keys instead of arrow keys.
So, I made a WASD patch.
Git url: https://github.com/zzoru/OpenTTD-TinyPatches

Usage
Just apply this patch & compile & execute :P (How to patch: viewtopic.php?f=33&t=21678)
Also, you need to modify hotkeys.cfg (Delete usage of wasd keys likes GLOBAL+A)

Tested on macOS Sierra
(and maybe available on Windows, Linux, etc....)

TODO
* Make a option menu for wasd feature enable/disable.
* Auto disable hotkeys using wasd keys.
* Configureable keymaps for scrolling mainview. (But need to renaming wasd patch to other :P)
* Code refactoring :)



You can use

Re: Patch: WASD patch v0.1

Posted: 01 Aug 2017 15:31
by Alberth
Why not make a patch that extends the hotkeys file?

Re: Patch: WASD patch v0.1

Posted: 01 Aug 2017 17:42
by zzoru
Alberth wrote:Why not make a patch that extends the hotkeys file?
That is one of my todo list.
I think that this patch is a fastest(also, easiest) way to apply wasd keys for scrolling mainview.
and also It seems that OpenTTD hotkey system doesn't completely support simultaneous alphabet key input now (Hotkey system needs to support it because of scrolling upleft, upright, etc...), isn't it? (I make some codes for testing this.)

Re: Patch: WASD patch v0.1

Posted: 01 Aug 2017 20:50
by zzoru
zzoru wrote:
Alberth wrote:Why not make a patch that extends the hotkeys file?
That is one of my todo list.
I think that this patch is a fastest(also, easiest) way to apply wasd keys for scrolling mainview.
and also It seems that OpenTTD hotkey system doesn't completely support simultaneous alphabet key input now (Hotkey system needs to support it because of scrolling upleft, upright, etc...), isn't it? (I make some codes for testing this.)
I make sample code using hotkey system.

src/video/cocoa/event.mm

Code: Select all

static Hotkey test_hotkeys[] = {
	Hotkey('W', "scroll_up", GHK_SCROLL_UP),
	Hotkey('S', "scroll_down", GHK_SCROLL_DOWN),
	Hotkey('A', "scroll_left", GHK_SCROLL_LEFT),
	Hotkey('D', "scroll_right", GHK_SCROLL_RIGHT),
	HOTKEY_LIST_END
};


HotkeyList *hotkeys = new HotkeyList("test", test_hotkeys);

static bool QZ_KeyEvent(unsigned short keycode, unsigned short unicode, BOOL down)
{
	bool interpret_keys = true;
	int hotkey = hotkeys->CheckMatch(QZ_MapKey(keycode));
	switch (hotkey) {
		case GHK_SCROLL_UP:   SB(_dirkeys, 1, 1, down); break; 
		case GHK_SCROLL_DOWN: SB(_dirkeys, 3, 1, down); break;
		case GHK_SCROLL_LEFT: SB(_dirkeys, 0, 1, down); break;
		case GHK_SCROLL_RIGHT: SB(_dirkeys, 2, 1, down); break;
	}

	switch (keycode) {
		case QZ_TAB: _tab_is_down = down; break;

		case QZ_RETURN:
		case QZ_f:
			if (down && (_current_mods & NSCommandKeyMask)) {
				VideoDriver::GetInstance()->ToggleFullscreen(!_fullscreen);
			}
			break;

		case QZ_v:
			if (down && EditBoxInGlobalFocus() && (_current_mods & (NSCommandKeyMask | NSControlKeyMask))) {
				HandleKeypress(WKC_CTRL | 'V', unicode);
			}
			break;
		case QZ_u:
			if (down && EditBoxInGlobalFocus() && (_current_mods & (NSCommandKeyMask | NSControlKeyMask))) {
				HandleKeypress(WKC_CTRL | 'U', unicode);
			}
			break;
	}
It works well, but it isn't clean code. I think that hotkey must be handled by OnHotKey API.
but, OnHotKey API can't handle simultaneous key input :(

Re: Patch: WASD patch v0.1

Posted: 04 Aug 2017 18:30
by adf88
zzoru wrote:I think that hotkey must be handled by OnHotKey API.
No. It seems that you took proper direction already.

Re: Patch: WASD patch v0.1

Posted: 04 Aug 2017 19:41
by zzoru
adf88 wrote:
zzoru wrote:I think that hotkey must be handled by OnHotKey API.
No. It seems that you took proper direction already.
I already made another patch. :P
https://github.com/zzoru/OpenTTD-TinyPa ... roll.patch

Re: Patch: WASD patch v0.1

Posted: 23 Aug 2019 01:33
by mantrangle
Hi.

I try to compile the code after applying the wasd patch but there are errors while compiling.
Annotation 2019-08-22 162649.png
Annotation 2019-08-22 162649.png (21.14 KiB) Viewed 5598 times
I'm using tortoiseSVN to download the latest source code and apply the patch, and VSC 2019 to compile.

Re: Patch: WASD patch v0.1

Posted: 23 Aug 2019 02:07
by kamnet
I'm not familiar with this patch at all, but considering the warnings are on four consecutive lines, I'm going to take a guess that the OpenTTD source code changed and that the code you need to modify is no longer on those line numbers. You may need to go through the source code and locate the new lines, then modify the patch.

Also, the original author hasn't visited this site since he last updated the patch in 2017. This patch may be DOA.

Re: Patch: WASD patch v0.1

Posted: 23 Aug 2019 12:07
by _dp_
I've played with wasd recently and fixed those errors. It's for citymania client though so line numbers can be off a bit.
https://bitbucket.org/citymania/cmclien ... 5e?at=wasd