Enable setting of new key bindings

This commit is contained in:
George Fleming
2016-04-27 11:00:45 -07:00
committed by Andrew Schwartzmeyer
parent 232f9abe54
commit 1c955a67a8
3 changed files with 21 additions and 3 deletions
@@ -690,7 +690,6 @@ namespace Microsoft.PowerShell
MethodInfo mi = typeof (PSConsoleReadLine).GetMethod(function);
var keyHandler = (Action<ConsoleKeyInfo?, object>)
mi.CreateDelegate(typeof (Action<ConsoleKeyInfo?, object>));
#else
var keyHandler = (Action<ConsoleKeyInfo?, object>)
Delegate.CreateDelegate(typeof (Action<ConsoleKeyInfo?, object>),
@@ -6,6 +6,9 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
#if CORECLR
using System.Reflection;
#endif
using System.Runtime.InteropServices;
using Microsoft.PowerShell.Internal;
@@ -211,7 +214,22 @@ namespace Microsoft.PowerShell
{
// default for unprintables and unhandled
char keyChar = '\u0000';
#if CORECLR
Type keyType = typeof (Keys);
FieldInfo[] keyFields = keyType.GetFields();
foreach (FieldInfo field in keyFields)
{
if (field.FieldType == typeof(ConsoleKeyInfo))
{
ConsoleKeyInfo info = (ConsoleKeyInfo)field.GetValue(null);
if (info.Key == key && info.Modifiers == modifiers)
{
return info.KeyChar;
}
}
}
#else
// emulate GetKeyboardState bitmap - set high order bit for relevant modifier virtual keys
var state = new byte[256];
state[NativeMethods.VK_SHIFT] = (byte)(((modifiers & ConsoleModifiers.Shift) != 0) ? 0x80 : 0);
@@ -234,7 +252,7 @@ namespace Microsoft.PowerShell
{
keyChar = chars[0];
}
#endif
return keyChar;
}
}
@@ -490,6 +490,7 @@ namespace Microsoft.PowerShell
dispatchTable.TryGetValue(key, out handler);
}
}
if (handler != null)
{
if (handler.ScriptBlock != null)