There are such bindings in mc.keymap, which don't describe a meaningful shift-like key combination, but something that looks like a raw character sequence that starts with a letter, and ends with a digit, e.g.:
Top = home; alt-g; a1 # ← the sequence in question, i.e.: "a1"
Bottom = end; alt-shift-g; c1
I wonder what do they describe, i.e.: how are they triggered? What key-combination is, e.g., "c1"?
A1 is the "Home" key on the keypad (numpad 7 with Num Lock turned off), which is decoded as a different key from the regular "Home". Likewise C1 is keypad "End", C1 is keypad "Page Up", C3 is keypad "Page Down", and B2 is documented to "center of keypad", i.e. the 5 key, though I don't know whether any keyboards actually use that. They are documented for the curses library here (search for "keypad").
Other libraries tend to name these keys something like KP_HOME, KP_END, etc. but curses took a different tack of caring more about the physical layout than the key labels. Midnight commander just inherited this from (n)curses.
In any case, it should be clear now why the "Top" command would get a default binding for both "home" and "a1" — they are the two keys labeled "Home" on a common PC keyboard.
Related
So I know that you can't directly get input from a user in a functional program because it obviously wouldn't be pure. But does this still apply if the user had only like 4 options to choose from?
For instance, is it still impure if you're asking for hair color and there were four options to choose from: Brown, Black, Blonde, Red. If the user were to click a button corresponding to their hair color instead of typing it in, would that be considered pure?
You can't predict what the user is going to choose, making the decision non-deterministic, and hence impure.
User input is essentially a function that has to produce a value out of nothing: () -> HairColor.
If you have four kinds of HairColor, you can write exactly four pure functions of that type:
f1 _ = Blonde
f2 _ = Brown
f3 _ = Black
f4 _ = Blue
None of them would, though, capture user input. In order to get the user input, you need another kind of 'argument' to the function:
UserInput -> HairColor
but then, where does UserInput come from? It's not something you can compile into the program. It has to 'come from the outside', and every time you run the program, it may be different.
I'm trying to code a trivial pursuit game. I want to give an id for every space of the board in order to use them for the movements. I need to know for every space which is next to which/match with each other.
But because of the geometry of the board(extern circle + radii), I didn't find the right logic behind this.
I am thinking of an ID based on 7 numbers (for the 6 radii + the circle). For example :
//this is not my code, i'm just trying to show example of IDs
center = [0][0][0][0][0][0][-2]
one on the "2nd radius" = [0][3][0][0][0][0][-2]
one the circle and the "3rd radius" = [0][0][6][0][0][0][22]
one on the circle = [0][0][0][0][0][0][21]
I have no idea if it's gonna work or if it's optimal, i will try and see.
If some of you have any better idea for name the ID, i would be happy to listen to them.
Here is an image of the board.
enter image description here
Thank you for helping!
OK, seeems you are inventing some coordinate system for this wheel for easy addressing and easy transtions between cells. System with many indices looks too complex.
Perhaps two-index scheme would be appropriate. Resembles polar coordinates:
The first index 0..6 as distance from the center.
The second one 1..42 - angular position.
So center cell is A[0][0] (the second index is not defined, we can choose any)
It's neighbors are A[1][1], A[1][8], A[1][15] ..A[1][36] (marked with 1 at your picture)
Similar for the next cells at the rays A[2][1], A[2][8], A[2][15] ..A[2][36] and so on
Wheel cells are A[6][1], A[6][2]..A[6][42]
Now neighbor cells have coordinates where one index differs by 1 (except for central cell, extra case)
Is this scheme suitable?
I want to detect where a pressed key physically is on a Mac keyboard. Looking at the keycode tells me the char etc. but not the location, which varies with language/keyboard layout. I'd need something like row indexes for the key.
I'm able to look at the keyboard layout language using this code:
TISInputSourceRef source = TISCopyCurrentKeyboardInputSource();
NSLog(#"localized name: %#", TISGetInputSourceProperty(source, kTISPropertyLocalizedName));
From which I could map location through building keycode location dictionaries for each language, but that could be a lot of work to cover most keyboards.
Any ideas for a shortcut?
You are incorrect about the key code. On OS X, the virtual key code corresponds to the key position. It does not indicate which character would be generated by the keyboard layout.
For example, key code 0 is kVK_ANSI_A. What this means is not that it is the key which produces the "A" character. It means it's the key which is in the position that the "A" key is on an ANSI standard keyboard. It's the leftmost key in the middle row of letter keys.
When key code 0 is translated through the French keyboard layout with no modifiers, it produces the "q" character.
I was wondering if you could receive keyboard input just like Java, C+, etc. Or if there isn't is there external libraries?
Here's some info on the 2D, Maze-Game:
You use the arrow keys to navigate through the maze. You use the UP and DOWN arrow keys to select the objects in the menu, for example:
--> New Game
Load Game
Options
And so on... I appreciate any help. Good day.
Lua on its own does not provide any libraries that aren't part of ANSI C, which is part of the extensive portability of the language.
As such, you miss out on things like keyboard input and graphics, but also operations that might be considered "simple," like listing the files in a directory.
Most likely, there's a library for what you need, and if there isn't, then keep in mind that Lua is one of the friendliest languages to write C-side libraries for.
LOVE is a good framework that couples quite a few extensions to Lua (including a rather abstracted interface to SDL) with a distribution method, more or less. If you're developing games with Lua, this is a good place to start.
EDIT: If you're on Windows with LuaJIT and you're okay with global key hooks, then I developed a library recently (May 2015) that solves that problem: https://github.com/LPGhatguy/global-keys
There are libraries like curses that may help; here is one tutorial one reading arrow keys with curses in Lua. There is also luaposix library, which includes curses.
I have answer if you use linux this code will work. just try my code on other platform see if it work(if you curious). It doesn't echo the arrow key and doesn't wait until you press enter.
Modify some my code if this cause some problem.
This might be very useful for your 2D maze project
function getch_unix() --This return key pressed instantly without waiting until user press enter key
os.execute("stty -echo raw")
os.execute("stty cbreak </dev/tty >/dev/tty 2>&1")
local key = io.read(3) --must read three letter for getArrowKey to work
os.execute("stty -cbreak </dev/tty >/dev/tty 2>&1");
return(key);
end
function getArrowKey()
function split(str)
local tmp = {}
for let in string.gmatch(str, ".") do
table.insert(tmp, let)
end
return tmp
end
--[[
A is up arrow
B is down arrow
D is left arrow
C is right arrow
]]
local key = split(getch_unix())
if string.lower(key[3]) == "a" then
return "up"
elseif string.lower(key[3]) == "b" then
return "down"
elseif string.lower(key[3]) == "d" then
return "left"
elseif string.lower(key[3]) == "c" then
return "right"
else
error("Invalid arrow key!")
end
end
I get this way when i exprimenting with getch_unix() function that i found on internet searching to get a pressed key without echoing at all and not waiting for you press enter button.
EDIT:
Im also found https://github.com/max1220/lua-getch it has several useful features for your use case more info at the git if my code still not fit with your use case it also shorthen your code
I am really stuck with some state based testing concepts...
I am trying to calculate some checking sequences that will cover all transitions from each state and i have the answers but i dont understand them:
alt text http://www.gam3r.co.uk/1m.jpg
Now the answers i have are :
alt text http://www.gam3r.co.uk/2m.jpg
I dont understand it at all. For example say we want to check transition a/x from s1, wouldnt we do ab only? As we are already in s1, we do a/x to test the transition to s2, then b to check we are in the previous right state(s1)? I cant understand why it is aba or even bb for s1...
Can anyone talk me through it?
Thanks
There are 2 events available in each of 4 states, giving 8 transitions, which the author has decided to test in 8 separate test sequences. Each sequence (except the S1 sequences - apparently the machine's initial state is S1) needs to drive the machine to the target state and then perform either event a or event b.
The sequences he has chosen are sufficient, in that each transition is covered. However, they are not unique, and - as you have observed - not minimal.
A more obvious choice would be:
a b
ab aa
aaa aab
ba bb
I don't understand the author's purpose in adding superfluous transitions at the end of each sequence. The system is a Mealy machine - the behaviour of the machine is uniquely determined by the current state and event. There is no memory of the path leading to the current state; therefore the author's extra transitions give no additional coverage and serve only to confuse.
You are also correct that you could cover the all transitions with a shorter set of paths through the graph. However, I would be disinclined to do that. Clarity is more important than optimization for test code.