- Subject: Keysyms in wjed and win32 console jed
- From: Marko Mahnic <marko.mahnic@xxxxxxxx>
- Date: Wed, 09 Nov 2005 12:10:17 +0100
Hi.
I added support for xterm keycodes to WJed and console jed (WIN32).
* use x_set_keysym to define a code for a key
* the default codes are the same as in xjed (xkeys.c is linked with wjed/jed)
* IBMPC_KEYBOARD is defined to distinguish between different versions of the keyboard
* library files were modified to use IBMPC_KEYBOARD
* XKEYSYM was added to makefile.all
* when NUMLOCK_IS_GOLD=1, NumLock returns a keycode
* keypad keys (0-9) can return different codes depending on the state of NumLock
To compile jed/wjed with keysym support, create a makefile with:
mkmake WIN32 MINGW32 DLL XKEYSYM <makefile.all >Makefile
(I only tested the code with the mingw compiler using SLang in a DLL).
After you make the binaries, you can test the keys with
wjed -n -l ./testkeysym.sl
(look inside the code; Ctrl-N toggles NUMLOCK_IS_GOLD).
Marko
private variable i;
private define xtest(key, name)
{
x_set_keysym(key, ' ', name);
x_set_keysym(key, '^', "C-" + name);
x_set_keysym(key, '$', "S-" + name);
x_set_keysym(key, '%', "CS-" + name);
}
xtest(0x0020, "SPC");
xtest(0xff08, "BS");
xtest(0xff09, "TAB");
xtest(0xff0d, "RET");
xtest(0xff1b, "ESC");
xtest(0xff7f, "NLck");
xtest(0xffaf, "Kdiv");
xtest(0xffaa, "Kmul");
xtest(0xffad, "Ksub");
xtest(0xffab, "Kadd");
xtest(0xff8d, "KRet");
for (i = 0; i < 10; i++) xtest(0xffb0 + i, sprintf("Kp%d", i));
xtest(0xff95, "KHom");
xtest(0xff97, "KUp");
xtest(0xff9A, "KPgU");
xtest(0xff96, "KLft");
xtest(0xff9D, "KBeg");
xtest(0xff98, "KRgt");
xtest(0xff9C, "KEnd");
xtest(0xff99, "KDn");
xtest(0xff9B, "KPgD");
xtest(0xff9e, "KIns");
xtest(0xff9f, "KDel");
for (i = 0; i < 12; i++) xtest(0xffbe + i, sprintf("F%d", i + 1));
xtest(0xff50, "Hom");
xtest(0xff51, "Lft");
xtest(0xff52, "Up");
xtest(0xff53, "Rgt");
xtest(0xff54, "Dn");
xtest(0xff55, "PgUp");
xtest(0xff56, "PgDn");
xtest(0xff57, "End");
xtest(0xff63, "Ins");
xtest(0xffff, "Del");
% NumLock is Gold (for EDT mode)
message("press Ctrl-N to toggle NumLock_Is_Gold");
setkey("toggle_gold", "^N");
setkey("toggle_gold", "^n");
define toggle_gold()
{
if (NUMLOCK_IS_GOLD) NUMLOCK_IS_GOLD = 0;
else NUMLOCK_IS_GOLD = 1;
if (NUMLOCK_IS_GOLD)
message("NUMLOCK_IS_GOLD is ON");
else
message("NUMLOCK_IS_GOLD is off");
}
% Conflicting codes
x_set_keysym(0x0008, '^', "C-H");
x_set_keysym(0x0009, '^', "C-I");
x_set_keysym(0x000a, '^', "C-J");
x_set_keysym(0x000d, '^', "C-M");
--- /cygdrive/s/jed/jed-B0.99-17.135/lib/emacs.sl 2005-10-24 04:56:54.000000000 +0200
+++ /cygdrive/s/jed/temp/build/jed/lib/emacs.sl 2005-11-09 09:04:30.656250000 +0100
@@ -37,7 +37,7 @@
% setkey("backward_delete_char", "^?");
setkey("backward_delete_char_untabify", "^?");
-#ifdef IBMPC_SYSTEM
+#ifdef IBMPC_KEYBOARD
setkey("smart_set_mark_cmd", "^@^C");
#else
setkey("smart_set_mark_cmd", "^@");
--- /cygdrive/s/jed/jed-B0.99-17.135/lib/help.sl 2005-10-24 04:56:54.000000000 +0200
+++ /cygdrive/s/jed/temp/build/jed/lib/help.sl 2005-11-09 09:04:30.671875000 +0100
@@ -60,7 +60,7 @@
{
i += 3;
switch (str)
-#ifndef IBMPC_SYSTEM
+#ifndef IBMPC_KEYBOARD
{ case "[[A" : "UP"; }
{ case "[[B" : "DOWN"; }
{ case "[[C" : "RIGHT"; }
--- /cygdrive/s/jed/jed-B0.99-17.135/lib/ide.sl 2005-10-24 04:56:54.000000000 +0200
+++ /cygdrive/s/jed/temp/build/jed/lib/ide.sl 2005-11-09 09:04:30.671875000 +0100
@@ -30,7 +30,7 @@
custom_variable ("Ide_Skippable_Chars",
"\n\t !\"#$%&'()*+,-./:;<=>?@[\]^`{|}~");
-#ifndef IBMPC_SYSTEM
+#ifndef IBMPC_KEYBOARD
private variable Key_BS_Del = "^?";
private variable Key_Alt_BS_Del = strcat("\e", Key_BS_Del);
#endif
@@ -73,7 +73,7 @@
setkey ("kbd_quit", "\e\e\e");
setkey ("ide_bdelete_word", Key_Alt_BS);
setkey ("list_buffers", "\e0");
-#ifndef IBMPC_SYSTEM
+#ifndef IBMPC_KEYBOARD
setkey ("ide_bdelete_word", Key_Alt_BS_Del);
#endif
setkey ("ide_bdelete_word", "\et"); % ESC-o is used for Mode menu
--- /cygdrive/s/jed/jed-B0.99-17.135/lib/isearch.sl 2005-10-24 04:56:54.000000000 +0200
+++ /cygdrive/s/jed/temp/build/jed/lib/isearch.sl 2005-11-09 09:04:30.687500000 +0100
@@ -246,7 +246,7 @@
ungetkey (c);
break;
}
-#ifdef IBMPC_SYSTEM
+#ifdef IBMPC_KEYBOARD
{
case 0xE0:
ungetkey (c);
--- /cygdrive/s/jed/jed-B0.99-17.135/lib/jed.sl 2005-10-24 04:56:54.000000000 +0200
+++ /cygdrive/s/jed/temp/build/jed/lib/jed.sl 2005-11-09 09:04:30.703125000 +0100
@@ -110,7 +110,7 @@
setkey ("goto_match", "^\\");
setkey ("undo", "^_");
-#ifndef IBMPC_SYSTEM
+#ifndef IBMPC_KEYBOARD
setkey("bob", "^K\eOA");
setkey("bob", "^K\e[A");
setkey("eob", "^K\eOB");
--- /cygdrive/s/jed/jed-B0.99-17.135/lib/keycode.sl 2005-10-24 04:56:54.000000000 +0200
+++ /cygdrive/s/jed/temp/build/jed/lib/keycode.sl 2005-11-09 09:04:30.703125000 +0100
@@ -39,7 +39,7 @@
switch (ch)
{ case 0: "^@"; }
{ case 27: "\\e"; }
-#ifdef IBMPC_SYSTEM
+#ifdef IBMPC_KEYBOARD
{ case 224: "\\xE0"; }
#endif
{
--- /cygdrive/s/jed/jed-B0.99-17.135/lib/keydefs.sl 2005-10-24 04:56:54.000000000 +0200
+++ /cygdrive/s/jed/temp/build/jed/lib/keydefs.sl 2005-11-09 09:04:30.718750000 +0100
@@ -5,7 +5,7 @@
% modified by GM <g.milde@xxxxxxxxxxxxxxxxxxxx>
% modified by JED
-#ifdef IBMPC_SYSTEM %{{{
+#ifdef IBMPC_KEYBOARD %{{{
variable Key_F1 = "^@;";
variable Key_F2 = "^@<";
variable Key_F3 = "^@=";
--- /cygdrive/s/jed/jed-B0.99-17.135/lib/menus.sl 2005-10-24 04:56:54.000000000 +0200
+++ /cygdrive/s/jed/temp/build/jed/lib/menus.sl 2005-11-09 09:04:30.734375000 +0100
@@ -16,7 +16,7 @@
menu_set_menu_bar_prefix ($1, "F10 key ==> ");
-#ifndef IBMPC_SYSTEM
+#ifndef IBMPC_KEYBOARD
setkey ("select_menubar", "\e[21~"); % F10
# ifdef UNIX
_for (0, 9, 1)
@@ -39,7 +39,7 @@
#ifdef UNIX
unset_setkey ("select_menubar", "^(k;)");
#else
-# ifdef IBMPC_SYSTEM
+# ifdef IBMPC_KEYBOARD
unset_setkey ("select_menubar", "^@D");
# endif
#endif
@@ -53,7 +53,7 @@
unset_setkey ("@\emi", "\ei");
unset_setkey ("@\emH", "\eh");
unset_setkey ("@\emy", "\ey");
-#ifdef IBMPC_SYSTEM
+#ifdef IBMPC_KEYBOARD
unset_setkey ("@\emF", "^@!"); % Alt-F
unset_setkey ("@\emE", "^@^R"); % Alt-E
unset_setkey ("@\emo", "^@^X"); % Alt-O
--- /cygdrive/s/jed/jed-B0.99-17.135/lib/mini.sl 2005-10-24 04:56:54.000000000 +0200
+++ /cygdrive/s/jed/temp/build/jed/lib/mini.sl 2005-11-09 09:04:30.734375000 +0100
@@ -150,7 +150,7 @@
!if (keymap_p (mini))
make_keymap (mini);
-#ifdef IBMPC_SYSTEM
+#ifdef IBMPC_KEYBOARD
definekey ("next_mini_command", "\eOr", mini);
definekey ("next_mini_command", "\xE0P", mini);
definekey ("prev_mini_command", "\xE0H", mini);
--- /cygdrive/s/jed/jed-B0.99-17.135/src/intrin.c 2005-10-24 04:56:54.000000000 +0200
+++ /cygdrive/s/jed/temp/build/jed/src/intrin.c 2005-11-09 09:04:30.671875000 +0100
@@ -1030,6 +1030,10 @@
SLdefine_for_ifdef ("IBMPC_SYSTEM");
#endif
+#ifdef IBMPC_KEYBOARD
+ SLdefine_for_ifdef ("IBMPC_KEYBOARD");
+#endif
+
#ifdef SIXTEEN_BIT_SYSTEM
SLdefine_for_ifdef("16_BIT_SYSTEM");
#endif
--- /cygdrive/s/jed/jed-B0.99-17.135/src/jedconf.h 2005-10-24 04:56:54.000000000 +0200
+++ /cygdrive/s/jed/temp/build/jed/src/jedconf.h 2005-11-09 09:04:30.703125000 +0100
@@ -82,6 +82,9 @@
# if defined(__GO32__) || defined(__CYGWIN32__)
# define HAVE_UNISTD_H
# endif
+# ifndef USE_X_KEYSYM
+# define IBMPC_KEYBOARD
+# endif
#endif
#if !defined(VMS) && !defined(__WATCOMC__)
--- /cygdrive/s/jed/jed-B0.99-17.135/src/keymap.c 2005-10-24 04:56:54.000000000 +0200
+++ /cygdrive/s/jed/temp/build/jed/src/keymap.c 2005-11-09 09:04:30.718750000 +0100
@@ -38,7 +38,7 @@
# include "menu.h"
#endif
-#ifdef IBMPC_SYSTEM
+#if defined (IBMPC_KEYBOARD)
# include "doskeys.h"
#endif
@@ -281,7 +281,7 @@
SLkm_define_key ("^[9", (FVOID_STAR) digit_arg, Global_Map);
SLkm_define_key ("^[0", (FVOID_STAR) digit_arg, Global_Map);
-#ifdef IBMPC_SYSTEM
+#if defined (IBMPC_KEYBOARD)
SLkm_define_key (PC_DEL, (FVOID_STAR) delete_char_cmd, Global_Map);
SLkm_define_key (PC_DEL1, (FVOID_STAR) delete_char_cmd, Global_Map);
SLkm_define_key (PC_NULL, (FVOID_STAR) set_mark_cmd, Global_Map);
@@ -331,7 +331,7 @@
SLkm_define_key ("^K^[[D", (FVOID_STAR) scroll_right, Global_Map);
SLkm_define_key ("^K^[[A", (FVOID_STAR) bob, Global_Map);
SLkm_define_key ("^K^[[B", (FVOID_STAR)eob, Global_Map);
-#if HAS_MOUSE
+#if defined(HAS_MOUSE) && !defined (IBMPC_SYSTEM)
SLkm_define_key ("\033[M", (FVOID_STAR)xterm_mouse_cmd, Global_Map);
#endif
#ifdef sun
--- /cygdrive/s/jed/jed-B0.99-17.135/src/menu.c 2005-10-24 04:56:54.000000000 +0200
+++ /cygdrive/s/jed/temp/build/jed/src/menu.c 2005-11-09 09:04:30.734375000 +0100
@@ -1778,7 +1778,7 @@
SLkm_define_key ("^Z", (FVOID_STAR) sys_spawn_cmd, Menu_Keymap);
SLkm_define_key ("^M", (FVOID_STAR) select_menu_cmd, Menu_Keymap);
-#ifndef IBMPC_SYSTEM
+#if !defined(IBMPC_KEYBOARD)
SLkm_define_key ("\033[A", (FVOID_STAR) up_menu_cmd, Menu_Keymap);
SLkm_define_key ("\033OA", (FVOID_STAR) up_menu_cmd, Menu_Keymap);
SLkm_define_key ("\033[B", (FVOID_STAR) down_menu_cmd, Menu_Keymap);
@@ -1797,7 +1797,7 @@
SLkm_define_key ("^(kP)", (FVOID_STAR) pgup_menu_cmd, Menu_Keymap);
SLkm_define_key ("^(kN)", (FVOID_STAR) pgdn_menu_cmd, Menu_Keymap);
# endif
-# ifdef HAS_MOUSE
+#if defined(HAS_MOUSE) && !defined (IBMPC_SYSTEM)
SLkm_define_key ("\033[M", (FVOID_STAR) xterm_mouse_cmd, Menu_Keymap);
# endif
#else /* IBMPC_SYSTEM */
--- /cygdrive/s/jed/jed-B0.99-17.135/src/mkfiles/makefile.all 2005-10-24 04:56:54.000000000 +0200
+++ /cygdrive/s/jed/temp/build/jed/src/mkfiles/makefile.all 2005-11-09 09:23:54.390625000 +0100
@@ -32,6 +32,7 @@
Features include (also edit features.h!)
NO_FOLD (The default is to get folding support)
+ XKEYSYM Use keysym in WJed and win32 console jed (with WIN32)
More will be added in the future.
@@ -153,6 +154,9 @@
! endif
!endif
!ifdef WIN32
+! ifdef XKEYSYM
+CFLAGS += -DUSE_X_KEYSYM
+! endif
! ifdef BCC #{{{
CC = bcc32
#CFLAGS = -G- -H -N -w -D__WIN32__ -W -DJED
--- /cygdrive/s/jed/jed-B0.99-17.135/src/w32cons.c 2005-10-24 04:56:54.000000000 +0200
+++ /cygdrive/s/jed/temp/build/jed/src/w32cons.c 2005-11-09 11:10:02.921875000 +0100
@@ -63,6 +63,62 @@
extern HANDLE _SLw32_Hstdin;
#endif
+static void _putkey(unsigned char c)
+{
+ buffer_keystring ((char *)&c, 1);
+}
+
+#ifdef USE_X_KEYSYM
+# include "wkeysym.c"
+
+static void process_key_event(KEY_EVENT_RECORD *key)
+{
+ unsigned int keycode, key_state = 0;
+ unsigned int scan;
+ unsigned char prefix, c1 = 0;
+ int i, state;
+ DWORD d = key->dwControlKeyState;
+
+ if (!key->bKeyDown) return;
+ if (d & LEFT_ALT_PRESSED) key_state |= KEY_ALT;
+ if (d & RIGHT_ALT_PRESSED) key_state |= KEY_ALT_GR;
+ if (d & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) key_state |= KEY_CONTROL;
+ if (d & SHIFT_PRESSED) key_state |= KEY_SHIFT;
+
+ scan = key->wVirtualScanCode;
+ if (d & ENHANCED_KEY)
+ scan |= 0x100;
+
+ keycode = scan_to_keysym(scan);
+
+ if (try_keysym_to_keyseq(keycode, key_state & (KEY_SHIFT | KEY_CONTROL | KEY_ALT))) return;
+
+#if 0 /* defined(__MINGW32__) */
+ c1 = key->AsciiChar;
+#else
+ c1 = key->uChar.AsciiChar;
+#endif
+ if (c1 != 0)
+ {
+ if (c1 == (char) Jed_Abort_Char)
+ {
+ if (Ignore_User_Abort == 0) SLang_set_error (USER_BREAK);
+ SLKeyBoard_Quit = 1;
+ }
+
+ if (c1 < 0x80)
+ if (try_keysym_to_keyseq(toupper(c1),
+ key_state & (KEY_SHIFT | KEY_CONTROL | KEY_ALT))) return;
+
+ if (key_state & KEY_ALT) _putkey('\033');
+ _putkey(c1);
+
+ return;
+ }
+}
+
+#else
+
static unsigned char f_keys[4][12] =
{
{ 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 133, 134 },
@@ -87,11 +143,6 @@
{ 'w', 'x', 'y', 0, 't', 'u', 'v', 0, 'q', 'r', 's', 'p', 'n' }
};
-static void _putkey(unsigned char c)
-{
- buffer_keystring ((char *)&c, 1);
-}
-
static void process_key_event(KEY_EVENT_RECORD *key)
{
unsigned int key_state = 0;
@@ -339,7 +390,7 @@
}
#endif
}
-
+#endif
static void process_mouse_event(MOUSE_EVENT_RECORD *mevent)
{
@@ -660,8 +711,24 @@
CloseHandle (pi.hThread);
}
+#ifdef USE_X_KEYSYM
+static SLang_Intrin_Fun_Type Jed_WinCons_Table[] =
+{
+ MAKE_INTRINSIC_IIS("x_set_keysym", x_set_keysym, VOID_TYPE),
+ MAKE_INTRINSIC(NULL, NULL, 0, 0)
+};
+#endif
+
int jed_init_w32_support (void)
{
+#ifdef USE_X_KEYSYM
+ if ((-1 == SLadd_intrin_fun_table(Jed_WinCons_Table, "WINCONS")))
+ return -1;
+ if (-1 == init_xkeys ())
+ {
+ }
+#endif
+
SLang_Interrupt = process_console_records;
return w32_init_subprocess_support (0);
}
--- /cygdrive/s/jed/jed-B0.99-17.135/src/wterm.c 2005-10-24 04:56:54.000000000 +0200
+++ /cygdrive/s/jed/temp/build/jed/src/wterm.c 2005-11-09 11:12:05.109375000 +0100
@@ -216,6 +216,10 @@
static void set_init_popup_callback(void);
static void msw_help(void);
+#ifdef USE_X_KEYSYM
+static void x_set_keysym (int*, int*, char*);
+#endif
+
static HINSTANCE hPrevInst;
static HINSTANCE hInstance;
static char *szJedSection = "WJED";
@@ -451,6 +455,10 @@
* 'keyword'
*/
+#ifdef USE_X_KEYSYM
+ MAKE_INTRINSIC_IIS("x_set_keysym", x_set_keysym, VOID_TYPE),
+#endif
+
MAKE_INTRINSIC(NULL, NULL, 0, 0)
};
#undef S
@@ -1701,6 +1709,31 @@
static int Ignore_Wchar_Message;
+#ifdef USE_X_KEYSYM
+# include "wkeysym.c"
+
+static LRESULT CALLBACK process_key_down (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ unsigned int scan, keycode;
+ unsigned int key_state = 0;
+
+ if (GetKeyState(VK_CONTROL) & 0x8000) key_state |= KEY_CONTROL;
+ if (GetKeyState(VK_SHIFT) & 0x8000) key_state |= KEY_SHIFT;
+ if (GetKeyState(VK_MENU) & 0x8000) key_state |= KEY_ALT;
+
+ Ignore_Wchar_Message = 0;
+
+ scan = (unsigned int) ((lParam >> 16) & 0x1FF);
+ keycode = scan_to_keysym(scan);
+
+ if (try_keysym_to_keyseq(keycode, key_state))
+ Ignore_Wchar_Message = 1;
+
+ return 0;
+}
+
+#else
+
static unsigned char f_keys[4][12] =
{
{ 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 133, 134 },
@@ -1927,6 +1960,7 @@
Ignore_Wchar_Message = 1;
return 0;
}
+#endif
static int load_dropped_files(HDROP hDrop, HWND hwnd)
{
@@ -2035,6 +2069,25 @@
if (Ignore_User_Abort == 0) SLang_set_error(USER_BREAK);
SLKeyBoard_Quit = 1;
}
+#ifdef USE_X_KEYSYM
+ if (! SLKeyBoard_Quit)
+ {
+ unsigned int key_state = 0;
+ if (GetKeyState(VK_CONTROL) & 0x8000) key_state |= KEY_CONTROL;
+ if (GetKeyState(VK_SHIFT) & 0x8000) key_state |= KEY_SHIFT;
+ if (GetKeyState(VK_MENU) & 0x8000) key_state |= KEY_ALT;
+
+ // keysym: 0x00??
+ if (wParam < 0x0080)
+ {
+ if (try_keysym_to_keyseq(toupper(wParam), key_state))
+ {
+ Ignore_Wchar_Message = 1;
+ break;
+ }
+ }
+ }
+#else
/* PS 28Apr98: handle shiftTAB same as DOS */
if (wParam == 0x009)
{
@@ -2046,6 +2099,7 @@
}
}
/* if (wParam == 0xE0) _putkey(wParam); */
+#endif
_putkey(wParam);
break;
}
@@ -2895,6 +2949,12 @@
if (Batch)
return;
+#ifdef USE_X_KEYSYM
+ if (-1 == init_xkeys ())
+ {
+ }
+#endif
+
memset ((char *) &tt, 0, sizeof (SLsmg_Term_Type));
tt.tt_normal_video = msw_normal_video;
[2005 date index]
[2005 thread index]
[Thread Prev] [Thread Next]
[Date Prev] [Date Next]