From ea05e5a4d6f5ccc9cf8ff8a613508ea4daaf8fc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Mon, 16 Dec 2013 21:32:31 +0100 Subject: [PATCH] fixed right alt for certain keyboard layouts not working as a modifier to input characters (e.g. the German layout, where it's needed for a couple of chars mainly in the numbers row), since it's actually emitting Alt+Ctrl, and when ctrl was pressed everything was treated like a key-combo; not resending control keys that are usually held down, to avoid packet spam (ctrl, alt, shift, meta) --- assets/opencomputers/lua/rom/bin/edit.lua | 4 +++- li/cil/oc/client/gui/Buffer.scala | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/assets/opencomputers/lua/rom/bin/edit.lua b/assets/opencomputers/lua/rom/bin/edit.lua index dd9d8e736..063b14574 100644 --- a/assets/opencomputers/lua/rom/bin/edit.lua +++ b/assets/opencomputers/lua/rom/bin/edit.lua @@ -225,6 +225,8 @@ local function enter() setStatus("Save: [Ctrl+S] Close: [Ctrl+W]") end +local controlKeyCombos = {[keyboard.keys.s]=true,[keyboard.keys.w]=true, + [keyboard.keys.c]=true,[keyboard.keys.x]=true} local function onKeyDown(char, code) if code == keyboard.keys.back and not readonly then if left() then @@ -252,7 +254,7 @@ local function onKeyDown(char, code) down(h - 1) elseif code == keyboard.keys.enter and not readonly then enter() - elseif keyboard.isControlDown() then + elseif keyboard.isControlDown() and controlKeyCombos[code] then local cbx, cby = getCursor() if code == keyboard.keys.s and not readonly then local new = not fs.exists(filename) diff --git a/li/cil/oc/client/gui/Buffer.scala b/li/cil/oc/client/gui/Buffer.scala index c40b4ced0..a100f2274 100644 --- a/li/cil/oc/client/gui/Buffer.scala +++ b/li/cil/oc/client/gui/Buffer.scala @@ -77,8 +77,10 @@ trait Buffer extends GuiScreen { } else if (Keyboard.getEventKeyState) { val char = Keyboard.getEventCharacter - PacketSender.sendKeyDown(buffer.owner, char, code) - pressedKeys += code -> char + if (!pressedKeys.contains(code) || !ignoreRepeat(char, code)) { + PacketSender.sendKeyDown(buffer.owner, char, code) + pressedKeys += code -> char + } } else pressedKeys.remove(code) match { case Some(char) => PacketSender.sendKeyUp(buffer.owner, char, code) @@ -94,4 +96,15 @@ trait Buffer extends GuiScreen { } protected def changeSize(w: Double, h: Double): Double + + private def ignoreRepeat(char: Char, code: Int) = { + code == Keyboard.KEY_LCONTROL || + code == Keyboard.KEY_RCONTROL || + code == Keyboard.KEY_LMENU || + code == Keyboard.KEY_RMENU || + code == Keyboard.KEY_LSHIFT || + code == Keyboard.KEY_RSHIFT || + code == Keyboard.KEY_LMETA || + code == Keyboard.KEY_RMETA + } }