Awesome wm - changing menubar's keybindings - keyboard-events

I have a keybinding which launches a default menubar in Awesome WM:
awful.key({ modkey }, "l", function() menubar.show() end,
I am using a non-qwerty keyboard layout (in this case lets take dvorak) and would like to change the default keybindings for moving left and right in the menubar to fit the vim-like controls for dvorak:
i.e. changing "j" to "h" and "k" to "t"
I have tried settings the hooks parameter in menubar.prompt_args:
local hooks = {
{{"Control"}, "h", awful.spawn.with_shell("sh -c "xdotool key ctrl+h)}
-- OR
... awful.key.execute("Control","j")
-- OR
... root.fake_input("key_press", "Control_L")
... root.fake_input("key_press", "j")
-- xdotool returns qwerty "j" for key "h" here
}
menubar.prompt_args = {
hooks = hooks
}
; as well as settings the keypressed_callback parameter:
menubar.prompt_args = {
keypressed_callback = function(mod, key, cmd)
if (mod.Control and key == "h") then
awful.spawn.with_shell("sh -c 'xdotool key ctrl+h'")
-- same as above key "h" returns "j" with xdotool
-- OR
awful.key.execute("Control","j")
-- OR
root.fake_input("key_press", "Control_L")
root.fake_input("key_press", "j")
end
end,
}
But there comes no feedback when pressing the respective key while a menubar is launched.
Does someone know if my code is faulty,
or if there is a better way to do this?

Related

Is there a way to use/get the value from a current entry window

I'm trying to get the variable that's entered in an entry widget on the Return key pressed event, but struggling a bit. What I have tried has always produced a blank result.
This code may look messy and hap-hazard, but it's only going to be a template that I'll be using on a current project!
I've tried that many things to get it to work, I can't remember what I have tried!
from collections import OrderedDict
try:
import tkinter as tk
except:
import Tkinter as tk
root = tk.Tk()
labelLIST = OrderedDict([
('Temp ID', 'tempID'),
('PO Number', "poNumber"),
('Reference', "reference"),
('Cut/Sample Date', "csDate"),
('Cut Number', "cut")
])
i = 0
e_loops = len(labelLIST)
print (e_loops)
def bval1(event=None):
for i in range(e_loops):
print (entries[i].get())
entries[0].delete(0, tk.END)
entries[0].insert(0, 'DISABLED')
entries[0].configure(state='disabled')
def bval2():
entries[0].configure(state='normal')
for i in range(e_loops):
entries[i].delete(0, tk.END)
entries[0].focus()
def onClick(event):
ent = event.widget # event.widget is the widget that called the event
print(ent.cget("text")) # Print the text for the selected button
event.widget.tk_focusNext().focus()
def enterEV(event):
# print(entries[].get())
event.widget.tk_focusNext().focus()
entries = []
for key, value in labelLIST.items():
label = tk.Label(root, text=key)
label.grid(row=i, column=0, sticky="ew", padx=1, pady=1)
entry = tk.Entry(root, width=10)
entry.grid(row=i, column=1, sticky="ew", padx=5, pady=5)
if value == "cut":
entry.bind('<Return>', bval1)
else:
# entry.bind('<Return>', enterEV)
entry.bind('<Return>', onClick)
entries.append(entry)
i = i+1
button = tk.Button(root, text="Submit", command=bval1)
button.grid(row=0, column=2, columnspan=9, sticky="ew")
button = tk.Button(root, text="Clear", command=bval2)
button.grid(row=1, column=2, columnspan=9, sticky="ew")
entries[0].focus()
tk.mainloop()
When enter/return is pressed, I want the value that is the entry box to be printed to terminal via the onClick event. But the output is always empty.
def onClick(event):
ent = event.widget # event.widget is the widget that called the event
print(ent.cget("text")) # Print the text for the selected button
event.widget.tk_focusNext().focus()
You don't use the text attribute to get the value in an Entry widget. Using cget("text") returns the value for the textvariable attribute. Since you haven't set that attribute, it will always be the empty string.
Instead, you need to call the get method:
print(ent.get())

How to use switch case in dictionary key values with iteration

I am trying to make an application for users to show their actions on timeLine.
My timeline library named StepProgressView hasn't delegate or dataSource. So I can't change text color in iteration with my keys.
There is a titleLabel and subtitleLabel in my timeLine library. If you want how it works you can check the library in this link
I have title and subTitle array on my project. When I add the titles in my array it gives me timeLine with array items.
I want to change titleLabel text color.
This is my dictionary output when i print it.
[17: "17 Kind of long rambling explanation that no one reads in reality",
14: "14 Kind of long rambling explanation that no one reads in reality",
20: "20 Kind of long rambling explanation that no one reads in reality"
I want to use if else statement for colors. If dict value is 17 text color should be red or something.
But when I iterate it fills with last color of key value. This is my problem. I hope its clear.
for (key, _) in self.stepDetails {
progressView.pastTextColor = getColor(key: key)
}
func getColor(key: Int) -> UIColor {
switch key {
case 0...key:
return .red
case key ... key + 10:
return .blue
default:
return .gray
}
}
It always gives last color because it's in iteration so
What is the best approach in this case ?
Thank you !

How can I detect the pressing of the Command or Option Key and the return key at the same time with ngKeypress?

I know I can do something like this:
<div class="contentView"
ng-keypress="phs.keyEnter($event)">
keyEnter = ($event): void => {
var a = $event;
var b = $event.keyCode;
}
But is there a way that I can detect if both the Command or Option key is pressed at the same time as the Return key?
The $event indicates some keys that were simultaneously pressed (such as ctrl, alt...).
https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/MouseEvent.
Not sure about cmd, but check it out.
You can also combine ngKeypress & ngKeyup to check when cmd key was pressed and return key was released and determine when those events overlap.

How to insert new item in empty array any position?

i have a table that is multiple selected allow. first time user select some row . second time user come beck this page deselect some row and may be selected some row or not . but i need to hold previous selected rows . that row indicated price . so i need to track price that is the reason table view selected row i am tracking .
Here i my declaration array empty :
var groupSelectedOldPrice : [String] = []
here is my table row selected index item price append to the array:
if addon?.isSelect == true {
cell.accessoryType = .checkmark
groupSelectedOldPrice[indexPath.row] = (addon?.price)! // Index out of range
}
when user press done button :
let selectedUserRows = self.tableView.indexPathsForSelectedRows
if let _selectedUserRows = selectedUserRows {
for select in _selectedUserRows {
print(select.row)
let dishprice = Double((dish?.price)!)! - Double(groupSelectedOldPrice[select.row])!
dish?.price = "\(dishprice)"
}
}
i am not sure How i can achieved this . should I use dictionary for key value
You are getting Array index is out of range error because you are trying to insert at discrete indexes (more like skipping intermediate indexes. But it doesn't work this way. You just can't have an array like ["a", "b", _ , _ , "g", "u", _ , _ , "y"])
Let's do one thing. You maintain a counter var, insert at that counter's position and then increment that counter. Something like:
var counter: Int = 0
...
groupSelectedOldPrice.insert("your string" at:counter)
counter = counter +1
...
EDIT
(Answered according to what you asked for)
To achieve your requirement, you can maintain a Dictionary. A Dictionary where key will be your indexpath.row and value will be your String. Pretty much like:
var dic: [Int:String] = [:] // it's your declaration
....
....
dic[indexpath.row] = "your string" // when you try to fill your dictionary
You can insert your element at a specific index of array
let index = 1
yourArray.insert("Your String", at: index)

Toggle a key with hotkey in autohotkey

So I tried to automate running in a game, where the map is huge, and I have to run miles. I wanted to toggle on the hotkey (Ctrl+Shift+A or something else) press the running (in the game, I can run with w).
I tried code, like:
Pause On
Loop
Send w
+^a::Pause
(it can press the w, but it can't release) and like this:
+^a::
toggle := !toggle
while toggle
Send {w down}
(same problem).
It's just my problem, or these codes are wrong?
I have a (at least i think) much simpler solution :)
#NoTrayIcon
ScrollLock::
Input, Key, ,{Enter}
Send, {%Key% Down}
return
You press ScrollLock (which I doubt you use for anything else, otherwise set it to a free key), and then enter the name of button to be held down.
If you want to hold down a single character, you just write it in.
For other keys you can find the names here: http://www.autohotkey.com/docs/KeyList.htm
Mouse: LButton for left, RButton for right and MButton for middle
You end the input with the Enter key, and after that the program will hold down the entered key.
If you want to "lift up" the key, just simply press it once, and it will be held down no more. :)
ps.:I have #NoTrayIcon, because I'm running it permanently in the background, but if you wanted to be able to exit then simply add something like this:
F12::
ExitApp
return
This is my stock function. I usualy map it to ^W or Q. Pressing w or s will cancel it. Easy peasy.
HoldW(){
SendInput {w up}{w down}
Loop
{
Sleep 100
GetKeyState state, w
if state = u
return
If GetKeyState("s")
{
SendInput {w up}
return
}
}
}
+^vk41:: ; shift+ctrl+a
SetTimer, % "SomeLable", % (bToggle:=!bToggle) ? 25:"Off"
KeyWait, % "vk41"
Return
SomeLable:
SendInput, % "{vk57}" ; w
Return
A silly noob example where F10 is the toggle hotkey, and the up/down state is a variable. The variable needs to be pre-declared to give the initial value.
To be honest I expected an error message, but it seemed to run fine.
keystate=down
F10::
Send {w %keystate%}
if keystate = down
SetEnv, keystate, up
else if keystate = up
SetEnv, keystate, down
return
Toggle := 1
Q::Send, % Toggle = 1 ? ( "0", Toggle := 0 ) : ( "9", Toggle := 1 )
Change Q to your preferred hotkey, and change "0" and "9" to the keys you want to toggle through. Make sure to set your abilities or weapons to the keys you replace in "0" and "9".
So, lets say I have a primary and secondary weapon. I bind them in game to 9 and 0.
I press Q to cycle between them for fast weapon switching. Or w/e else you want.

Resources