當前位置: 首頁>>代碼示例>>Golang>>正文


Golang keybind.KeyMatch函數代碼示例

本文整理匯總了Golang中github.com/BurntSushi/xgbutil/keybind.KeyMatch函數的典型用法代碼示例。如果您正苦於以下問題:Golang KeyMatch函數的具體用法?Golang KeyMatch怎麽用?Golang KeyMatch使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了KeyMatch函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: keyResponse

// keyResponse translates key board input into two different actions: canceling
// the current prompt and making a choice in the cycle prompt.
// Canceling a prompt corresponds to the "CycleConfig.CancelKey" being pressed.
// Making a choice in the cycle prompt corresponds to releasing all of the
// modifiers used to initiate showing the prompt (when "CycleConfig.AutoChoose"
// is true).
// If CancelKey is empty, then no cancel key functionality is provided.
// If AutoChoose is false, then releasing the modifiers will have no effect.
//
// For thos interested in the X details:
// The prompt cycle dialog needs to choose the selection when the
// modifiers (i.e., "alt" in "alt-tab") are released.
// The only way to do this (generally) is to check the raw KeyRelease event.
// Namely, if the keycode *released* is a modifier, we have to and-out
// that modifier from the key release event data. If the modifiers
// remaining aren't up to snuff with the original grabbed modifiers,
// then we can finally "choose" the selection.
// TL;DR - This is how we "exit" the prompt cycle dialog.
func (cycle *Cycle) keyResponse() xevent.KeyReleaseFun {
	f := func(X *xgbutil.XUtil, ev xevent.KeyReleaseEvent) {
		if !cycle.showing {
			return
		}

		mods, kc := keybind.DeduceKeyInfo(ev.State, ev.Detail)

		// If the key release is the cancel key, quit the prompt and
		// don't do anything.
		if keybind.KeyMatch(X, cycle.config.CancelKey, mods, kc) {
			cycle.Hide()
			return
		}

		mods &= ^keybind.ModGet(X, ev.Detail)
		if cycle.grabMods > 0 {
			if mods&cycle.grabMods == 0 {
				cycle.Choose()
			}
		} else {
			if keybind.KeyMatch(X, cycle.config.ConfirmKey, mods, kc) {
				cycle.Choose()
			}
		}
	}
	return xevent.KeyReleaseFun(f)
}
開發者ID:mkrull,項目名稱:wingo,代碼行數:46,代碼來源:cycle.go

示例2: keyPress

func (ct *CommandTray) keyPress() xevent.KeyPressFun {
	f := func(X *xgbutil.XUtil, ev xevent.KeyPressEvent) {

		//		print("Cake:\n")

		if !ct.is_focused {
			//			print("Boom\n")
			return
		}

		mods, kc := keybind.DeduceKeyInfo(ev.State, ev.Detail)

		//		print("Key Press:", mods, kc, "\n")

		switch {
		case keybind.KeyMatch(X, "Escape", mods, kc):
			ct.Blur()

		case keybind.KeyMatch(X, "Return", mods, kc):
			ct.activate()

		case keybind.KeyMatch(X, "Up", mods, kc):
			ct.selected -= 1
			if ct.selected < 0 {
				ct.selected = len(ct.cmds)
			}
			ct.Draw()

		case keybind.KeyMatch(X, "Down", mods, kc):
			if len(ct.cmds) > 0 {
				ct.selected += 1
				ct.selected %= len(ct.cmds)
				ct.Draw()
			}

		case keybind.KeyMatch(X, "BackSpace", mods, kc):
			if len(ct.input) > 0 {

				ct.input = ct.input[:len(ct.input)-1]

				ct.getCommands()

				ct.Draw()
			}

		default:
			s := keybind.LookupString(X, mods, kc)
			if len(s) == 1 {
				ct.input = append(ct.input, rune(strings.ToLower(s)[0]))
				ct.selected = 0

				ct.getCommands()

				ct.Draw()
			}
		}
	}

	return xevent.KeyPressFun(f)
}
開發者ID:AmandaCameron,項目名稱:gobar,代碼行數:60,代碼來源:commandtray.go

示例3: keyResponse

func (slct *Select) keyResponse() xevent.KeyPressFun {
	f := func(X *xgbutil.XUtil, ev xevent.KeyPressEvent) {
		if !slct.showing {
			return
		}

		beforeLen := len(slct.input.Text)
		mods, kc := keybind.DeduceKeyInfo(ev.State, ev.Detail)

		slct.input.Add(mods, kc)

		switch {
		case keybind.KeyMatch(X, slct.config.BackspaceKey, mods, kc):
			slct.input.Remove()
		case keybind.KeyMatch(X, slct.config.CancelKey, mods, kc):
			slct.Hide()
			return
		case keybind.KeyMatch(X, slct.config.ConfirmKey, mods, kc):
			if slct.selected >= 0 && slct.selected < len(slct.items) {
				slct.items[slct.selected].choose()
				slct.Hide()
			} else if len(slct.items) == 1 {
				slct.items[0].choose()
				slct.Hide()
			}
			return
		case keybind.KeyMatch(X, "Tab", mods, kc) ||
			keybind.KeyMatch(X, "ISO_Left_Tab", mods, kc):

			if len(slct.items) == 0 {
				break
			}
			if mods&xproto.ModMaskShift > 0 {
				if slct.selected == -1 {
					slct.selected++
				}
				slct.selected = misc.Mod(slct.selected-1, len(slct.items))
			} else {
				slct.selected = misc.Mod(slct.selected+1, len(slct.items))
			}
			slct.highlight()
		}

		// If the length of the input changed, then re-evaluate completion
		if beforeLen != len(slct.input.Text) {
			slct.FilterItems(string(slct.input.Text))
			slct.selected = -1
			slct.highlight()
		}
	}
	return xevent.KeyPressFun(f)
}
開發者ID:cshapeshifter,項目名稱:wingo,代碼行數:52,代碼來源:select.go

示例4: keyResponse

func (msg *Message) keyResponse() xevent.KeyPressFun {
	f := func(X *xgbutil.XUtil, ev xevent.KeyPressEvent) {
		if !msg.showing {
			return
		}

		mods, kc := keybind.DeduceKeyInfo(ev.State, ev.Detail)
		switch {
		case keybind.KeyMatch(X, msg.config.ConfirmKey, mods, kc):
			fallthrough
		case keybind.KeyMatch(X, msg.config.CancelKey, mods, kc):
			msg.Hide()
		}
	}
	return xevent.KeyPressFun(f)
}
開發者ID:flying99999,項目名稱:wingo,代碼行數:16,代碼來源:message.go

示例5: keyResponse

func (inp *Input) keyResponse() xevent.KeyPressFun {
	f := func(X *xgbutil.XUtil, ev xevent.KeyPressEvent) {
		if !inp.showing {
			return
		}

		mods, kc := keybind.DeduceKeyInfo(ev.State, ev.Detail)
		switch {
		case keybind.KeyMatch(X, "Up", mods, kc):
			if inp.historyIndex > 0 {
				inp.historyIndex--
				inp.input.SetString(inp.history[inp.historyIndex])
			}
		case keybind.KeyMatch(X, "Down", mods, kc):
			if inp.historyIndex < len(inp.history) {
				inp.historyIndex++
				if inp.historyIndex < len(inp.history) {
					inp.input.SetString(inp.history[inp.historyIndex])
				} else {
					inp.input.Reset()
				}
			}
		case keybind.KeyMatch(X, inp.config.BackspaceKey, mods, kc):
			inp.input.Remove()
		case keybind.KeyMatch(X, inp.config.ConfirmKey, mods, kc):
			if inp.do != nil {
				s := string(inp.input.Text)
				histLen := len(inp.history)

				// Don't added repeated entries.
				if histLen == 0 || s != inp.history[histLen-1] {
					inp.history = append(inp.history, s)
				}
				inp.do(inp, s)
			}
		case keybind.KeyMatch(X, inp.config.CancelKey, mods, kc):
			if inp.canceled != nil {
				inp.canceled(inp)
			}
			inp.Hide()
		default:
			inp.input.Add(mods, kc)
		}
	}
	return xevent.KeyPressFun(f)
}
開發者ID:Pursuit92,項目名稱:wingo,代碼行數:46,代碼來源:input.go

示例6: main

func main() {
	X, err := xgbutil.NewConn()
	if err != nil {
		log.Println(err)
		return
	}

	//Initialize the keybind package
	keybind.Initialize(X)

	//Create a window
	win, err := xwindow.Generate(X)
	if err != nil {
		log.Fatalf("Could not generate a new window X id: %s", err)
	}
	win.Create(X.RootWin(), 0, 0, 1024, 768, xproto.CwBackPixel, 0x606060ff)

	// Listen for Key{Press,Release} events.
	win.Listen(xproto.EventMaskKeyPress, xproto.EventMaskKeyRelease)

	// Map the window. This is what makes it on the screen
	win.Map()

	//Make a ...callback... for the events and connect
	xevent.KeyPressFun(
		func(X *xgbutil.XUtil, e xevent.KeyPressEvent) {
			modStr := keybind.ModifierString(e.State)
			keyStr := keybind.LookupString(X, e.State, e.Detail)
			if len(modStr) > 0 {
				log.Printf("Key: %s-%s\n", modStr, keyStr)
			} else {
				log.Println("Key:", keyStr)
			}

			if keybind.KeyMatch(X, "Escape", e.State, e.Detail) {
				if e.State&xproto.ModMaskControl > 0 {
					log.Println("Control-Escape detected. Quitting...")
					xevent.Quit(X)
				}
			}
		}).Connect(X, win.Id)

	//So here i'm going to try to make a image..'
	img := xgraphics.New(X, image.Rect(0, 0, 1024, 768))

	err = img.XSurfaceSet(win.Id)
	if err != nil {
		log.Printf("Error while setting window surface to image %d: %s\n",
			win, err)
	} else {
		log.Printf("Window %d surface set to image OK\n", win)
	}

	// I /think/ XDraw actually sends data to server?
	img.XDraw()
	// I /think/ XPaint tells the server to paint image to window
	img.XPaint(win.Id)

	//Start the routine that updates the window
	go updater(img, win)

	//This seems to start a main loop for listening to xevents
	xevent.Main(X)
}
開發者ID:auroralaboratories,項目名稱:corona-api,代碼行數:64,代碼來源:main.go

示例7: main

func main() {
	X, err := xgbutil.NewConn()
	fatal(err)

	// Remember to always initialize the keybind package before usage.
	keybind.Initialize(X)

	// We create a benign parent window. Its only value in this example is
	// instructional. In particular, it shows how to have a sub-window get
	// focus using the ICCCM WM_TAKE_FOCUS protocol. (Since by default,
	// the window manager will assign focus to your top-level window.)
	// The real magic happens below with the WMTakeFocus method call.
	parentWin, err := xwindow.Create(X, X.RootWin())
	fatal(err)

	// NewInput creates a new input window and handles all of the text drawing
	// for you. It can be any width, but the height will be automatically
	// determined by the height extents of the font size chosen.
	input := text.NewInput(X, parentWin.Id, width, padding, font, fontSize,
		fontColor, bgColor)
	parentWin.Resize(input.Geom.Width(), input.Geom.Height())

	// Make sure X reports KeyPress events when this window is focused.
	input.Listen(xproto.EventMaskKeyPress)

	// Listen to KeyPress events. If it's a BackSpace, remove the last
	// character in the input box. If it's "Return" quit. If it's "Escape",
	// clear the input box.
	// Otherwise, try to add the key pressed to the input box.
	// (Not all key presses correspond to a single character that is added.)
	xevent.KeyPressFun(
		func(X *xgbutil.XUtil, ev xevent.KeyPressEvent) {
			mods, kc := ev.State, ev.Detail
			switch {
			case keybind.KeyMatch(X, "BackSpace", mods, kc):
				input.Remove()
			case keybind.KeyMatch(X, "Return", mods, kc):
				log.Println("Return has been pressed.")
				log.Printf("The current text is: %s", string(input.Text))
				log.Println("Quitting...")
				xevent.Quit(X)
			case keybind.KeyMatch(X, "Escape", mods, kc):
				input.Reset()
			default:
				input.Add(mods, kc)
			}
		}).Connect(X, input.Id)

	// Implement the WM_DELETE_WINDOW protocol.
	parentWin.WMGracefulClose(func(w *xwindow.Window) {
		xevent.Quit(X)
	})

	// Implement the WM_TAKE_FOCUS protocol. The callback function provided
	// is executed when a valid WM_TAKE_FOCUS ClientMessage event has been
	// received from the window manager.
	// According to ICCCM Section 4.2.7, this is one of the three valid ways
	// of setting input focus to a sub-window. (It's also easiest since it
	// doesn't require us to monitor FocusChange events. EW.)
	// If you have multiple sub-windows that can be focused, this callback
	// function is where the logic would go to pick which sub-window should
	// be focused upon receipt of a WM_TAKE_FOCUS message.
	parentWin.WMTakeFocus(func(w *xwindow.Window, tstamp xproto.Timestamp) {
		input.FocusParent(tstamp)
	})

	// Map the window and start the main X event loop.
	input.Map()
	parentWin.Map()
	xevent.Main(X)
}
開發者ID:mkrull,項目名稱:wingo,代碼行數:71,代碼來源:main.go


注:本文中的github.com/BurntSushi/xgbutil/keybind.KeyMatch函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。