mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Enable setting of new key bindings
This commit is contained in:
committed by
Andrew Schwartzmeyer
parent
232f9abe54
commit
1c955a67a8
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user