Up key in Dos console in text mode
Posted: Mon Mar 04, 2024 9:32 pm
Good morning,
Is there a way to make the up key do nothing in a Dos console in text mode?
Is there a way to make the up key do nothing in a Dos console in text mode?
http://www.purebasic.com
https://www.purebasic.fr/english/
Sorry you didn't yet receive a reply, A_Carignan, you posted this last week and I started to reply, but never got around to sending it. The way I've implemented a console user interface, is to poll for my own keypresses and build my input string, rather than relying on Input(). The below may help, if this is something you want to do instead.a_carignan wrote: Mon Mar 04, 2024 9:32 pm Good morning,
Is there a way to make the up key do nothing in a Dos console in text mode?
Code: Select all
inpkey.s = Inkey() ; Returns ASCII input
inpascii.i = Asc(inpkey.s) ; ASCII value of inpkey
keycode.b = RawKey() ; Returns keyboard code if input is not a conventional ASCII inputIf you use EnableGraphicalConsole(1) then you'll achieve what you need. The graphical console isn't always suitable, depending on one's other needs. I remember in my case, for other technical reasons, I was unable to use it. It doesn't allow text wrapping beyond the right margin, if my memory is correct.a_carignan wrote: Sat Mar 16, 2024 8:15 pm Thank you, but what I would like to know is if we can remove the effect of the up key in a Dos console in text mode, without going through manual key management. The effect I want to get rid of is the fact that the up key causes the previously written text to be displayed. While I would like it to do nothing or at best go up one line.
Code: Select all
OpenConsole()
EnableGraphicalConsole(1)
Repeat
Input()
ForEver
Code: Select all
EnableExplicit
Enumeration
#event_enter
#event_escape
EndEnumeration
Define Semaphore = CreateSemaphore()
Define thread
Define event
If OpenLibrary(0, "Kernel32.dll")
Prototype GetConsoleWindow()
;Define GetConsoleWindow.GetConsoleWindow = GetFunction(0, "GetConsoleWindow")
Global GetConsoleWindow.GetConsoleWindow = GetFunction(0, "GetConsoleWindow")
CloseLibrary(0)
;Else
;MessageRequester("<Kernel32.dll> non trouvé.",#PB_MessageRequester_Error)
EndIf
Procedure onevent(event1)
Shared event,Semaphore
event=event1
SignalSemaphore(Semaphore)
EndProcedure
Procedure resizewindowid()
Define trect.rect,x,y,w,h
GetWindowRect_(getconsolewindow(),@trect)
x = trect\left
y = trect\top
w = trect\right - x
h = trect\bottom - y
ResizeWindow(0,x+w/2-WindowWidth(0)/2,y+h/2-WindowHeight(0)/2,#PB_Ignore,#PB_Ignore)
EndProcedure
Procedure activewindow_byhwnd(hwnd)
SendMessage_(GetForegroundWindow_(), #WM_SYSCOMMAND, #SC_HOTKEY, hwnd)
SetForegroundWindow_(hwnd)
BringWindowToTop_(hwnd)
SendMessage_(hwnd,#WM_ACTIVATE,0,0)
EndProcedure
Procedure.s inputbox(defaut.s)
Shared event,semaphore
SetGadgetText(1,defaut)
SendMessage_(GadgetID(1),#EM_SETSEL,0,Len(GetGadgetText(1)))
HideWindow(0,#False)
;SetActiveWindow(0)
activewindow_byhwnd(WindowID(0))
SetActiveGadget(1)
AddKeyboardShortcut(0,#PB_Shortcut_Return,#event_enter)
AddKeyboardShortcut(0,#PB_Shortcut_Escape,#event_escape)
WaitSemaphore(Semaphore)
RemoveKeyboardShortcut(0,#PB_Shortcut_All)
HideWindow(0,#True)
activewindow_byhwnd(GetConsoleWindow())
If event=#event_enter
ProcedureReturn GetGadgetText(1)
Else
ProcedureReturn defaut
EndIf
EndProcedure
Procedure execute(*valeur)
Define defaut.s
Repeat
Print("Default value? ")
defaut=inputbox(Input())
PrintN(defaut)
Until defaut="quit"
EndProcedure
OpenConsole()
If OpenWindow(0, 0, 0, 220, 100, "Exemple...", #PB_Window_BorderLess|#PB_Window_WindowCentered,getconsolewindow())
;ButtonGadget (1, 10, 60, 200, 30, "Fermer")
EditorGadget(1, 10, 10, 200, 80,#PB_Editor_WordWrap)
activewindow_byhwnd(WindowID(0))
SetActiveGadget(1)
HideWindow(0,#True)
resizewindowid()
AddWindowTimer(0,0,1)
thread=CreateThread(@execute(),0)
Repeat
Select WaitWindowEvent()
Case #PB_Event_Gadget
Select EventGadget()
Case 1
;CloseWindow(0)
;End
EndSelect
Case #PB_Event_Timer
Select EventTimer()
Case 0
resizewindowid()
If Not IsThread(thread)
Break
EndIf
EndSelect
Case #PB_Event_Menu
Select EventMenu()
Case #event_enter
onevent(#event_enter)
Case #event_escape
onevent(#event_escape)
EndSelect
Case #PB_Event_CloseWindow
Break
EndSelect
ForEver
EndIf