Skip to content
Snippets Groups Projects
Commit 5a588260 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Merge branch 'dd_lightbar_menu_nomoues_traditional_input' into 'master'

Better handling of ESC key input if mouse support is disabled

See merge request !130
parents 3adb964d 2e9cd51b
No related branches found
No related tags found
2 merge requests!463MRC mods by Codefenix (2024-10-20),!130Better handling of ESC key input if mouse support is disabled
...@@ -234,6 +234,13 @@ If you want to set the currently selected item before calling GetVal() to allow ...@@ -234,6 +234,13 @@ If you want to set the currently selected item before calling GetVal() to allow
you should call the SetSelectedItemIdx() function and pass the index to that. you should call the SetSelectedItemIdx() function and pass the index to that.
lbMenu.SetSelectedItemIdx(5); lbMenu.SetSelectedItemIdx(5);
The property inputTimeoutMS sets the input timeout in milliseconds (defaults to 300000).
lbMenu.inputTimeoutMS = 300000; // 300,000 milliseconds (5 minutes)
The property mouseEnabled can be used to enable mouse support. By default it is false.
When mouse support is enabled, there can be problems inputting the ESC key from the user.
lbMenu.mouseEnabled = true;
For selecting an item, it may be desirable to validate whether a user should be allowed For selecting an item, it may be desirable to validate whether a user should be allowed
to select the item. DDLightbarMenu has a member function it calls, ValidateSelectItem(), to select the item. DDLightbarMenu has a member function it calls, ValidateSelectItem(),
to do just that. It takes the selected item's return value and returns a boolean to signify to do just that. It takes the selected item's return value and returns a boolean to signify
...@@ -427,9 +434,8 @@ function DDLightbarMenu(pX, pY, pWidth, pHeight) ...@@ -427,9 +434,8 @@ function DDLightbarMenu(pX, pY, pWidth, pHeight)
// (i.e. with ENTER; not for toggling with multi-select) // (i.e. with ENTER; not for toggling with multi-select)
this.exitOnItemSelect = true; this.exitOnItemSelect = true;
// Things for mouse support this.inputTimeoutMS = 300000; // Input timeout in ms
this.mouseTimeout = 0; // Timeout in ms. Currently using 0 for no timeout. this.mouseEnabled = false;
this.mouseEnabled = false; // To pass to mouse_getkey
// Member functions // Member functions
this.Add = DDLightbarMenu_Add; this.Add = DDLightbarMenu_Add;
...@@ -1133,8 +1139,12 @@ function DDLightbarMenu_GetVal(pDraw, pSelectedItemIndexes) ...@@ -1133,8 +1139,12 @@ function DDLightbarMenu_GetVal(pDraw, pSelectedItemIndexes)
// TODO: With mouse_getkey(), it seems you need to press ESC twice // TODO: With mouse_getkey(), it seems you need to press ESC twice
// to get the ESC key and exit the menu // to get the ESC key and exit the menu
var mk = mouse_getkey(K_NOECHO|K_NOSPIN|K_NOCRLF, this.mouseTimeout > 1 ? this.mouseTimeout : undefined, this.mouseEnabled); var inputMode = K_NOECHO|K_NOSPIN|K_NOCRLF;
var mk = null; // Will be used for mouse support
var mouseNoAction = false; var mouseNoAction = false;
if (this.mouseEnabled)
{
mk = mouse_getkey(inputMode, this.inputTimeoutMS > 1 ? this.inputTimeoutMS : undefined, this.mouseEnabled);
if (mk.mouse !== null) if (mk.mouse !== null)
{ {
// See if the user clicked anywhere in the region where items are // See if the user clicked anywhere in the region where items are
...@@ -1228,6 +1238,11 @@ function DDLightbarMenu_GetVal(pDraw, pSelectedItemIndexes) ...@@ -1228,6 +1238,11 @@ function DDLightbarMenu_GetVal(pDraw, pSelectedItemIndexes)
// mouse is null, so a keybaord key must have been pressed // mouse is null, so a keybaord key must have been pressed
this.lastUserInput = mk.key; this.lastUserInput = mk.key;
} }
}
else // this.mouseEnabled is false
{
this.lastUserInput = getKeyWithESCChars(inputMode, this.inputTimeoutMS);
}
// If no further input processing needs to be done due to a mouse click // If no further input processing needs to be done due to a mouse click
// action, then continue to the next loop iteration. // action, then continue to the next loop iteration.
...@@ -1240,8 +1255,14 @@ function DDLightbarMenu_GetVal(pDraw, pSelectedItemIndexes) ...@@ -1240,8 +1255,14 @@ function DDLightbarMenu_GetVal(pDraw, pSelectedItemIndexes)
// Only exit if there was not a no-action mouse click // Only exit if there was not a no-action mouse click
// TODO: Is this logic good and clean? // TODO: Is this logic good and clean?
var goAheadAndExit = true; var goAheadAndExit = true;
if (mk.mouse !== null) if (mk !== null && mk.mouse !== null)
{
goAheadAndExit = !mouseNoAction; // Only really needed with an input timer? goAheadAndExit = !mouseNoAction; // Only really needed with an input timer?
// Temporary
console.print("\1n\r\nHere! - mouseNoAction: " + goAheadAndExit + ", goAheadAndExit: " + goAheadAndExit + "\r\n");
console.pause();
// End Temporary
}
if (goAheadAndExit) if (goAheadAndExit)
{ {
continueOn = false; continueOn = false;
...@@ -2584,3 +2605,74 @@ function printedToRealIdxInStr(pStr, pIdx) ...@@ -2584,3 +2605,74 @@ function printedToRealIdxInStr(pStr, pIdx)
} }
return realIdx; return realIdx;
} }
// Inputs a keypress from the user and handles some ESC-based
// characters such as PageUp, PageDown, and ESC. If PageUp
// or PageDown are pressed, this function will return the
// string defined by KEY_PAGE_UP or EY_PAGE_DOWN,
// respectively. Also, F1-F5 will be returned as "\1F1"
// through "\1F5", respectively.
// Thanks goes to Psi-Jack for the original impementation
// of this function.
//
// Parameters:
// pGetKeyMode: Optional - The mode bits for console.getkey().
// If not specified, K_NONE will be used.
// pInputTimeoutMS: The input timeout in milliseconds (defaults to 300000).
// If the user is a sysop, this will use a timeout of 0 for no timeout.
//
// Return value: The user's keypress
function getKeyWithESCChars(pGetKeyMode, pInputTimeoutMS)
{
var getKeyMode = (typeof(pGetKeyMode) === "number" ? pGetKeyMode : K_NONE);
var inputTimeoutMS = (typeof(pInputTimeoutMS) === "number" ? pInputTimeoutMS : 300000);
if (inputTimeoutMS == 0)
inputTimeoutMS = 300000;
// Input a key from the user and take action based on the user's input. If
// the user is a sysop, don't use an input timeout.
var userInput = "";
if (user.compare_ars("SYSOP"))
userInput = console.getkey(getKeyMode);
else
userInput = console.inkey(getKeyMode, inputTimeoutMS);
if (userInput == KEY_ESC)
{
switch (console.inkey(K_NOECHO|K_NOSPIN, 2))
{
case '[':
switch (console.inkey(K_NOECHO|K_NOSPIN, 2))
{
case 'V':
userInput = KEY_PAGE_UP;
break;
case 'U':
userInput = KEY_PAGE_DOWN;
break;
}
break;
case 'O':
switch (console.inkey(K_NOECHO|K_NOSPIN, 2))
{
case 'P':
userInput = KEY_F1;
break;
case 'Q':
userInput = KEY_F2;
break;
case 'R':
userInput = KEY_F3;
break;
case 'S':
userInput = KEY_F4;
break;
case 't':
userInput = KEY_F5;
break;
}
default:
break;
}
}
return userInput;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment