Patch: WASD patch v0.1

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Post Reply
zzoru
Engineer
Engineer
Posts: 5
Joined: 01 Aug 2017 10:33

Patch: WASD patch v0.1

Post by zzoru » 01 Aug 2017 11:39

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
Last edited by zzoru on 04 Aug 2017 19:50, edited 3 times in total.

Alberth
OpenTTD Developer
OpenTTD Developer
Posts: 4738
Joined: 09 Sep 2007 05:03
Location: home

Re: Patch: WASD patch v0.1

Post by Alberth » 01 Aug 2017 15:31

Why not make a patch that extends the hotkeys file?
Being a OpenTTD developer does not mean I know what I am doing.
Also, other OpenTTD developers may have different opinions.

zzoru
Engineer
Engineer
Posts: 5
Joined: 01 Aug 2017 10:33

Re: Patch: WASD patch v0.1

Post by zzoru » 01 Aug 2017 17:42

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.)

zzoru
Engineer
Engineer
Posts: 5
Joined: 01 Aug 2017 10:33

Re: Patch: WASD patch v0.1

Post by zzoru » 01 Aug 2017 20:50

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 :(

User avatar
adf88
Chief Executive
Chief Executive
Posts: 644
Joined: 14 Jan 2008 15:51
Location: PL

Re: Patch: WASD patch v0.1

Post by adf88 » 04 Aug 2017 18:30

zzoru wrote:I think that hotkey must be handled by OnHotKey API.
No. It seems that you took proper direction already.
:] don't worry, be happy and checkout my patches

zzoru
Engineer
Engineer
Posts: 5
Joined: 01 Aug 2017 10:33

Re: Patch: WASD patch v0.1

Post by zzoru » 04 Aug 2017 19:41

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

mantrangle
Engineer
Engineer
Posts: 1
Joined: 22 Aug 2019 08:21

Re: Patch: WASD patch v0.1

Post by mantrangle » 23 Aug 2019 01:33

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 299 times
I'm using tortoiseSVN to download the latest source code and apply the patch, and VSC 2019 to compile.

User avatar
kamnet
Moderator
Moderator
Posts: 6775
Joined: 28 Sep 2009 17:15
Location: Eastern KY
Contact:

Re: Patch: WASD patch v0.1

Post by kamnet » 23 Aug 2019 02:07

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.

_dp_
Engineer
Engineer
Posts: 123
Joined: 18 Dec 2013 12:32

Re: Patch: WASD patch v0.1

Post by _dp_ » 23 Aug 2019 12:07

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

Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: Google [Bot] and 2 guests