2020-02-15 20:01:48 +00:00
|
|
|
|
U0 PutKey(I64 ch=0,I64 sc=0)
|
|
|
|
|
{//See $LK,"Keyboard Devices",A="HI:Keyboard Devices/System"$.
|
2020-02-20 23:40:10 +00:00
|
|
|
|
CKeyDevEntry *tmpk;
|
|
|
|
|
if (ch||sc) {
|
|
|
|
|
tmpk=keydev.put_key_head.next;
|
|
|
|
|
if (!Bt(&Fs->display_flags,DISPLAYf_SILENT)) {
|
|
|
|
|
if (kbd.scan_code & SCF_SCROLL && sys_focus_task==Fs)
|
|
|
|
|
while (kbd.scan_code & SCF_SCROLL)
|
|
|
|
|
Yield; //Wait on SCROLL LOCK Key
|
|
|
|
|
while (tmpk!=&keydev.put_key_head) {
|
|
|
|
|
if ((!(sc&SCF_KEY_DESC) || tmpk->flags & KDF_HAS_DESCS) &&
|
|
|
|
|
(*tmpk->put_key)(ch,sc))
|
|
|
|
|
break;
|
|
|
|
|
tmpk=tmpk->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-15 20:01:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
U0 PutChars(U64 ch)
|
|
|
|
|
{//Output chars. Up to 8 chars in a single U64.
|
2020-02-16 05:24:10 +00:00
|
|
|
|
//Don't use this. $LK,"See Print() shortcut.",A="FF:::/Doc/CosmiC.DD,DemoCosmiC"$
|
2020-02-20 23:40:10 +00:00
|
|
|
|
while (ch) {
|
|
|
|
|
PutKey(ch&255,0);
|
|
|
|
|
ch>>=8;
|
|
|
|
|
}
|
2020-02-15 20:01:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
U0 PutS(U8 *st)
|
|
|
|
|
{//Use $LK,"Print",A="MN:Print"$(). See $LK,"Keyboard Devices",A="HI:Keyboard Devices/System"$.
|
2020-02-20 23:40:10 +00:00
|
|
|
|
//Don't use this. $LK,"See Print() shortcut.",A="FF:::/Doc/CosmiC.DD,DemoCosmiC"$
|
|
|
|
|
I64 ch;
|
|
|
|
|
U8 *ptr;
|
|
|
|
|
Bool cont=TRUE;
|
|
|
|
|
if (!st) return;
|
|
|
|
|
CKeyDevEntry *tmpk=keydev.put_key_head.next;
|
|
|
|
|
if (!Bt(&Fs->display_flags,DISPLAYf_SILENT)) {
|
|
|
|
|
if (kbd.scan_code & SCF_SCROLL && sys_focus_task==Fs)
|
|
|
|
|
while (kbd.scan_code & SCF_SCROLL)
|
|
|
|
|
Yield;
|
|
|
|
|
while (cont && tmpk!=&keydev.put_key_head) {
|
|
|
|
|
if (tmpk->put_s) {
|
|
|
|
|
if ((*tmpk->put_s)(st))
|
|
|
|
|
break;
|
|
|
|
|
} else {
|
|
|
|
|
ptr=st;
|
|
|
|
|
while (ch=*ptr++)
|
|
|
|
|
if ((*tmpk->put_key)(ch,0))
|
|
|
|
|
cont=FALSE;
|
|
|
|
|
}
|
|
|
|
|
tmpk=tmpk->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-02-15 20:01:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-16 03:06:00 +00:00
|
|
|
|
U0 KeyDescSet(U8 *format,...)
|
2020-02-15 23:56:05 +00:00
|
|
|
|
{//Call this from key handler to report desc in $LK,"KeyMap",A="MN:KeyMap"$().
|
2020-02-20 23:40:10 +00:00
|
|
|
|
U8 *buf=StrPrintJoin(NULL,format,argc,argv);
|
|
|
|
|
StrCopy(keydev.desc,buf);
|
|
|
|
|
keydev.handler=Caller;
|
|
|
|
|
Free(buf);
|
2020-02-15 20:01:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-15 23:13:27 +00:00
|
|
|
|
U0 KeyDevRemove(CKeyDevEntry *tmpk)
|
2020-02-15 20:01:48 +00:00
|
|
|
|
{//Remove StdOut hook and free.
|
2020-02-20 23:40:10 +00:00
|
|
|
|
QueueRemove(tmpk);
|
|
|
|
|
Free(tmpk);
|
2020-02-15 20:01:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CKeyDevEntry *KeyDevAdd(Bool (*fp_put_key)(I64 ch,I64 sc),
|
2020-02-20 23:40:10 +00:00
|
|
|
|
Bool (*fp_puts)(U8 *st),I64 priority,Bool key_descs=FALSE)
|
2020-02-15 20:01:48 +00:00
|
|
|
|
{//Places hook in StdOut chain. See $LK,"Keyboard Devices",A="HI:Keyboard Devices/System"$.
|
2020-02-20 23:40:10 +00:00
|
|
|
|
CKeyDevEntry *tmpk=keydev.put_key_head.last,
|
|
|
|
|
*tmpk1=ZCAlloc(sizeof(CKeyDevEntry));
|
|
|
|
|
tmpk1->put_key=fp_put_key;
|
|
|
|
|
tmpk1->put_s=fp_puts;
|
|
|
|
|
tmpk1->priority=priority;
|
|
|
|
|
if (key_descs)
|
|
|
|
|
tmpk1->flags|=KDF_HAS_DESCS;
|
|
|
|
|
while (tmpk->priority>priority)
|
|
|
|
|
tmpk=tmpk->last;
|
|
|
|
|
QueueInsert(tmpk1,tmpk);
|
|
|
|
|
if (tmpk->priority==priority)
|
|
|
|
|
KeyDevRemove(tmpk);
|
|
|
|
|
return tmpk1;
|
2020-02-15 20:01:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Bool KDRawPutKey(I64 ch,I64)
|
|
|
|
|
{
|
2020-02-20 23:40:10 +00:00
|
|
|
|
if (IsRaw) {
|
|
|
|
|
RawPutChar(ch);
|
|
|
|
|
return TRUE;
|
|
|
|
|
} else
|
|
|
|
|
return FALSE;
|
2020-02-15 20:01:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Bool KDRawPutS(U8 *st)
|
|
|
|
|
{
|
2020-02-20 23:40:10 +00:00
|
|
|
|
I64 ch;
|
|
|
|
|
if (IsRaw) {
|
|
|
|
|
while (ch=*st++)
|
|
|
|
|
RawPutChar(ch);
|
|
|
|
|
return TRUE;
|
|
|
|
|
} else
|
|
|
|
|
return FALSE;
|
2020-02-15 20:01:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Bool KDInputFilterPutKey(I64 ch,I64 scan_code)
|
|
|
|
|
{
|
2020-02-20 23:40:10 +00:00
|
|
|
|
if (Bt(&Fs->task_flags,TASKf_INPUT_FILTER_TASK)) {
|
|
|
|
|
Message(MESSAGE_KEY_DOWN,ch,scan_code);
|
|
|
|
|
return TRUE;
|
|
|
|
|
} else
|
|
|
|
|
return FALSE;
|
2020-02-15 20:01:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Bool KDInputFilterPutS(U8 *st)
|
|
|
|
|
{
|
2020-02-20 23:40:10 +00:00
|
|
|
|
I64 ch;
|
|
|
|
|
if (Bt(&Fs->task_flags,TASKf_INPUT_FILTER_TASK)) {
|
|
|
|
|
while (ch=*st++)
|
|
|
|
|
Message(MESSAGE_KEY_DOWN,ch,0);
|
|
|
|
|
return TRUE;
|
|
|
|
|
} else
|
|
|
|
|
return FALSE;
|
2020-02-15 20:01:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
U0 CtrlAltDel(I64)
|
|
|
|
|
{
|
2020-02-20 23:40:10 +00:00
|
|
|
|
LBts(sys_ctrl_alt_flags,CTRL_ALT_DEL);
|
2020-02-15 20:01:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
U0 CtrlAltC(I64)
|
|
|
|
|
{
|
2020-02-20 23:40:10 +00:00
|
|
|
|
LBts(sys_ctrl_alt_flags,CTRL_ALT_C);
|
2020-02-15 20:01:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
U0 CtrlAltD(I64)
|
|
|
|
|
{
|
2020-02-20 23:40:10 +00:00
|
|
|
|
if (!IsDebugMode) {
|
|
|
|
|
if (Fs==Gs->idle_task)
|
|
|
|
|
BptS(sys_winmgr_task->rip,sys_winmgr_task);
|
|
|
|
|
else
|
|
|
|
|
BptS(*keydev.ctrl_alt_ret_addr);
|
|
|
|
|
}
|
2020-02-15 20:01:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
U0 CtrlAltF(I64)
|
|
|
|
|
{
|
2020-02-20 23:40:10 +00:00
|
|
|
|
SwapI64(&text.font,&text.aux_font);
|
2020-02-15 20:01:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
U0 CtrlAltM(I64)
|
|
|
|
|
{
|
2020-02-20 23:40:10 +00:00
|
|
|
|
Mute(!IsMute);
|
2020-02-15 20:01:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
U0 CtrlAltN(I64)
|
|
|
|
|
{
|
2020-02-20 23:40:10 +00:00
|
|
|
|
LBts(sys_ctrl_alt_flags,CTRL_ALT_TAB);
|
2020-02-15 20:01:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
U0 CtrlAltT(I64)
|
|
|
|
|
{
|
2020-02-20 23:40:10 +00:00
|
|
|
|
User;
|
2020-02-15 20:01:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
U0 CtrlAltV(I64)
|
|
|
|
|
{
|
2020-02-21 03:36:04 +00:00
|
|
|
|
VBEFlush;
|
2020-02-15 20:01:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
U0 CtrlAltX(I64)
|
|
|
|
|
{
|
2020-02-20 23:40:10 +00:00
|
|
|
|
LBts(sys_ctrl_alt_flags,CTRL_ALT_X);
|
2020-02-15 20:01:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-15 23:56:05 +00:00
|
|
|
|
U0 CtrlAltCBSet(U8 ch,U0 (*fp_handler)(I64 sc),
|
2020-02-20 23:40:10 +00:00
|
|
|
|
U8 *no_shift_desc=NULL,U8 *shift_desc=NULL,Bool in_irq=FALSE)
|
2020-02-15 20:01:48 +00:00
|
|
|
|
{//Set callback for <CTRL-ALT-letter>.
|
2020-02-20 23:40:10 +00:00
|
|
|
|
ch=ToUpper(ch)-'A';
|
|
|
|
|
if (ch<26) {
|
|
|
|
|
keydev.fp_ctrl_alt_cbs[ch]=fp_handler;
|
2020-02-15 20:01:48 +00:00
|
|
|
|
|
2020-02-20 23:40:10 +00:00
|
|
|
|
Free(keydev.ctrl_alt_no_shift_descs[ch]);
|
|
|
|
|
if (no_shift_desc)
|
|
|
|
|
keydev.ctrl_alt_no_shift_descs[ch]=ZStrNew(no_shift_desc);
|
|
|
|
|
else
|
|
|
|
|
keydev.ctrl_alt_no_shift_descs[ch]=NULL;
|
2020-02-15 20:01:48 +00:00
|
|
|
|
|
2020-02-20 23:40:10 +00:00
|
|
|
|
Free(keydev.ctrl_alt_shift_descs[ch]);
|
|
|
|
|
if (shift_desc)
|
|
|
|
|
keydev.ctrl_alt_shift_descs[ch]=ZStrNew(shift_desc);
|
|
|
|
|
else
|
|
|
|
|
keydev.ctrl_alt_shift_descs[ch]=NULL;
|
2020-02-15 20:01:48 +00:00
|
|
|
|
|
2020-02-20 23:40:10 +00:00
|
|
|
|
BEqual(&keydev.ctrl_alt_in_irq_flags,ch,in_irq);
|
|
|
|
|
}
|
2020-02-15 20:01:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
U0 KeyDevInit()
|
|
|
|
|
{
|
2020-02-20 23:40:10 +00:00
|
|
|
|
keydev.fp_ctrl_alt_cbs =CAlloc(26*sizeof(U8 *));
|
|
|
|
|
keydev.ctrl_alt_no_shift_descs=CAlloc(26*sizeof(U8 *));
|
|
|
|
|
keydev.ctrl_alt_shift_descs =CAlloc(26*sizeof(U8 *));
|
|
|
|
|
keydev.ctrl_alt_in_irq_flags =0;
|
|
|
|
|
MemSet(&keydev.put_key_head,0,sizeof(CKeyDevEntry));
|
|
|
|
|
QueueInit(&keydev.put_key_head);
|
|
|
|
|
KeyDevAdd(&KDInputFilterPutKey,&KDInputFilterPutS,0x40000000,FALSE);
|
|
|
|
|
KeyDevAdd(&KDRawPutKey,&KDRawPutS,0x60000000,FALSE);
|
|
|
|
|
CtrlAltCBSet('C',&CtrlAltC,"Cmd/Break Execution",,TRUE);
|
|
|
|
|
CtrlAltCBSet('D',&CtrlAltD,"Cmd/Enter Debugger",,TRUE);
|
|
|
|
|
CtrlAltCBSet('F',&CtrlAltF,"Cmd/Toggle Aux Font");
|
|
|
|
|
CtrlAltCBSet('M',&CtrlAltM,"Cmd/Toggle Mute");
|
|
|
|
|
CtrlAltCBSet('N',&CtrlAltN,"Cmd/Next Focus Task",,TRUE);
|
|
|
|
|
CtrlAltCBSet('T',&CtrlAltT,"Cmd/Terminal Window");
|
|
|
|
|
CtrlAltCBSet('V',&CtrlAltV,"Cmd/VGA Flush",,TRUE);
|
|
|
|
|
CtrlAltCBSet('X',&CtrlAltX,"Cmd/Kill Focused Task",,TRUE);
|
2020-02-15 20:01:48 +00:00
|
|
|
|
}
|