Inkey
Posted
#1
(In Topic #116)
Guru

Posted
Regular

cogier said
How do I capture a key…
This may depend upon the type of cli program. If you use gb.ncurses to make a simple window (like alsamixer) you can respond to events and test the result.
Public Sub qWindow_Read()
Dim iKey As Integer = Window.Read()
If iKey = Key["r"] Then…
Take a look at my recent blog post: Captain Bodgit: Gambas cli programming: ncurses text based user interface
Posted
Regular

- Immissione di dati dalla tastiera durante l'esecuzione di un programma - Gambas-it.org - Wikipedia
- Individuare i tasti della tastiera intercettando i dati grezzi dal suo file-device - Gambas-it.org - Wikipedia
- Individuare i tasti premuti della tastiera mediante le risorse esterne delle librerie ioctl.h e termio.h - Gambas-it.org - Wikipedia
- Individuare i tasti premuti della tastiera mediante le risorse esterne dichiarate in termios.h - Gambas-it.org - Wikipedia
Europaeus sum !
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Posted
Guru

I have been looking at http://rosettacode.org/wiki/Rosetta_Code and adding code to the site and this is the 'Task' that I am trying to complete. http://www.rosettacode.org/wiki/Handle_a_signal. The site encouraged me to write the 15 Puzzle Game that is here http://rosettacode.org/wiki/15_Puzzle_Game#Gambas and on the Gambas Farm.
Posted
Regular

cogier said
…I would like to press 'Esc', or some other key, to stop the program running….
I think you need to use the gb.signal component: /comp/gb.signal - Gambas Documentation
I thought I had some example code, but cant find it at the moment. Will try to take a look later.
Posted
Guru

The code is
Code (gambas)
- With hTimer
- .Delay = 500
- .Start
- fTime += 0.5
I have put it on the Rosetta site here http://www.rosettacode…ki/Handle_a_signal#Gambas
Posted
Regular

cogier said
…I do feel there must/should be an easier way to capture a keypress…
Well, the task was about responding to signals, not just reading a key combination (I think some of the programs listed could only check the keys, not respond to signals).
In your example I'd get rid of the "With" & "End With" lines, as it saves 2 lines of code. It probably only makes sense to use this combo if you have 3 or more properties or methods to set/execute.
All-in-all I think your Gambas example stands up very well against the other listed languages on the Handle a signal - Rosetta Code page.
Well done!
You could also remove some of the blank lines to make it look more compact.
Posted
Guru

If you do include it the IDE tells you that "x is an unused argument". :?
While creating this post I discovered that if the program is run the error occurs but if you press [F5] again there is no complaint!!
I'll put a bug report on the 'other' forum.
You do have a point regarding the 'With hTimer..'. I set it up this way so that I could add other properties if needed but they weren't!
Posted
Regular

cogier said
Interesting point the "x As Integer" issue….
I didn't check whether it would work without it properly…then when it didn't, I tried to correct my post hoping you hadn't already read it. Sorry!
cogier said
You do have a point regarding the 'With hTimer..'. I set it up this way so that I could add other properties if needed…
…I do exactly the same thing.
Just been looking at all the tasks on that website. Makes you think us Gambasers should pull our fingers out and get coding, and start adding more examples to the list!
Posted
Guru

I didn't check whether it would work without it properly…then when it didn't, I tried to correct my post hoping you hadn't already read it. Sorry!
You had me worried I was thinking 'I am sure he mentioned this'!
Makes you think us Gambasers should pull our fingers out and get coding, and start adding more examples to the list!
I have been working at it. Have a look here http://rosettacode.org/wiki/Category:Gambas. Quite a bit of this is my code. Unfortunately there is someone who has put up Gambas code that wont run and with incorrect comments. Have a look here http://rosettacode.org/wiki/Arrays#Gambas.
Let us know if you put any code up.
Posted
Regular

Hi Cogier,
Are you still looking for an inkey function?
The attached project is incomplete, but has the information you need. The trick is to set the terminal to non-canonical so it doesn't wait for a newline to send.
Ced
.... and carry a big stick!
1 guest and 0 members have just viewed this.



