khchen / wNim

Nim's Windows GUI Framework
MIT License
327 stars 17 forks source link

Menu hotkey not work #81

Closed leeooox closed 3 years ago

leeooox commented 3 years ago

If I want to use Ctrl-N as hot key to create a new file and Ctrl-O to open a file, what is the correct method? I tried with this code, but it seems that press Ctrl-N on keyboard cannot active the event.

menu.append(idNew,"N&ew\tCtrl-N","New File")

Here is simple code to reproduce the issue.

import wNim/[wApp, wFrame, wPanel, wMenubar]

type
  MenuID = enum
    idNew = wIdUser, idOpen , idSave

let app = App()
let frame = Frame(title="Menu hokey test",size=(800,600))

let menuBar = MenuBar(frame)
let menu = Menu(menuBar, "&File")
menu.append(idNew,"N&ew\tCtrl-N","New File")
menu.append(idOpen,"&Open\tCtrl-O","Open File")
menu.append(idSave,"&Save\tCtrl-S","Save File")

let panel = Panel(frame)

frame.wEvent_Menu do (event: wEvent):
  if event.id == idNew:
    echo "New File"
  elif event.id == idOpen:
    echo "Open File"
  elif event.id == idSave:
    echo "Save File"
  else:
    echo "unexpected event"

frame.center()
frame.show()
app.mainLoop()
khchen commented 3 years ago

https://khchen.github.io/wNim/wAcceleratorTable.html https://github.com/khchen/wNim/blob/master/examples/frame.nim#L26

leeooox commented 3 years ago

@khchen Thanks very much, the wAcceleratorTable works.